You need to sign in to do that
Don't have an account?
Mahesh Tandan 6
does validation require in both page and controller?
I have a visualforce page and a custom controller
vf page have a form and required fields and i'm validating it throught <apex:inputtext value="{!data}" required="true">
my question is do I need to validate it in my controller also?
like if
please help.
vf page have a form and required fields and i'm validating it throught <apex:inputtext value="{!data}" required="true">
my question is do I need to validate it in my controller also?
like if
if(data == Null || data == ''){ pexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'my error message')); }i'm really confused about it.
please help.
The simple answer is if you've marked it as required on VF page then it will be required field and you need no to handle on controller side.
But just imagine a situation, where you want to reuse same controller on the other VF page. If you don't want that field to be as required on that VF page don't use this attribute.
So, it depends on you're requirement.
Thanks,
Ashish Singh.
All Answers
No you can handle it in VF page.
For better understanding please execute below code in your org and you can see validation error.
=======================================================
<apex:page standardController="Contact">
<apex:form>
<apex:messages/>
<apex:pageBlock title="PageBlock" mode="edit">
<apex:pageBlockSection title="Page block section">
<apex:outputLabel value="Birth date" for="mId"/>
<apex:outputPanel styleClass="requiredInput" layout="block">
<apex:outputPanel styleClass="requiredBlock" layout="block"/>
<apex:inputText value="{!contact.Birthdate}" required="true" id="mId"/>
</apex:outputPanel>
</apex:pageBlockSection>
<apex:pageblockButtons>
<apex:commandButton action="{!save}" value="save"></apex:commandButton>
</apex:pageblockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
==========================================================
Hope this helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks,
Vinay Kumar
The simple answer is if you've marked it as required on VF page then it will be required field and you need no to handle on controller side.
But just imagine a situation, where you want to reuse same controller on the other VF page. If you don't want that field to be as required on that VF page don't use this attribute.
So, it depends on you're requirement.
Thanks,
Ashish Singh.
Well Thank you Ashish Singh sfdc
your answer helped me