How to show required symbol in apex:inputText?

How to show required symbol in apex:inputText?

Sample Code:


Visualforce Page:
<apex:page controller=”Sample”>
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection >
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value=”Test Label”/>
                    <apex:outputPanel styleClass=”requiredInput” layout=”block” >
                        <apex:outputPanel styleClass=”requiredBlock” layout=”block”/>
                        <apex:inputText value=”{!str}” required=”true”/> 
                    </apex:outputpanel>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>

</apex:page>


Apex Class:
public with sharing class Sample { 


    public String str {Get;set;}
    
    public Sample() {
    }    
    
}


Output:



Cheers!!!

Leave a Reply