<apex:pageBlockSectionItem >
<apex:outputLabel value="Status" for="Status"/>
<apex:outputPanel styleClass="requiredInput" layout="block">
<apex:outputPanel styleClass="requiredBlock" layout="block"/>
<apex:selectList id="chooseStatus" value="{!Contact_Exemption_ACU__c.Status__c}" size="1" required="true" >
<apex:selectOption itemValue="Approved" itemLabel="Approved"/>
<apex:selectOption itemValue="Closed" itemLabel="Closed"/>
</apex:selectList>
</apex:outputPanel>
</apex:pageBlockSectionItem>
Hey, above is the code to get the red mark for an reqd attribute. Although I have used an standard field, any field can be used in the value in Select List. Also, if you need to display the error message later,following is the code.
<apex:outputPanel styleClass="requiredInput" layout="block">
<apex:inputField id="ACU_held_in_Customer" value="{!Contact_Exemption_ACU__c.ACU_held_in_Customer__c}"/>
<apex:outputPanel styleClass="errorMsg" layout="block" rendered="{!errorACUheldInCustomer}">
<strong>Error:</strong> {!errorMessage}
</apex:outputPanel>
</apex:outputPanel>
After doing the validation in the Controller, set the errorACUheldInCustomer to true and set the errorMessage.
以上摘自https://developer.salesforce.com/forums/ForumsMain?id=906F000000095BZIAY
打開debug工具,分析:一般sfdc标準的元件,隻要加上required=true就會出現如圖變紅的渲染效果。
在自定義的字段裡是沒有如圖的兩個div的,以上解決方法就是把連個class放出來了。