You need to sign in to do that
Don't have an account?
kurtz_wolfgang
pageMessages and validation error messages
hello all,
I need your expert guidance in the following matter.
here's my two sets of codes from Apex class:
if (!isValidUserName()){ ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Username should be a valid email address.'); ApexPages.addMessage(msg); return null; } private boolean isValidUserName(){ String at = '@'; String dot = '.'; Integer iLenAt = username.indexOf(at); Integer iLenDot = username.indexOf(dot,iLenAt); if(username.indexOf(at) <= 0 || username.indexOf(at) == username.length() || username.indexOf(dot) <= 0 || username.indexOf(dot) == username.length() || username.substring(iLenAt+1,iLenAt+2)==dot || username.indexOf(dot,(iLenAt+2))==-1 || username.indexOf(' ') !=-1 ){ return false; } return true; } /*----------------------------------------*/ public boolean checkFirstName(){ if (first_Name.length() == 0 ){ // ApexPages.Message msgFirstName = new ApexPages.Message(ApexPages.Severity.INFO, 'First Name is required.', 'First Name is required.'); ApexPages.Message msgFirstName = new ApexPages.Message(ApexPages.Severity.ERROR, Label.First_Name_Required); ApexPages.addMessage(msgFirstName); bRetVal= false; } }
my visualforce page contains the following components:
<tr> <td> <apex:outputLabel value="First Name: " for="firstName" styleClass="applicationInformationLabelRequired"/> </td> <td> <apex:inputText required="true" id="firstName" value="{!firstName}" size="25"/> </td> </tr> <tr> <td> <apex:outputLabel value="{!$Label.site.username}/Email: " for="username" styleClass="applicationInformationLabelRequired"/> </td> <td> <apex:inputText required="true" id="username" value="{!username}" size="25"/> </td> </tr>
both set of codes are similar and simple however for firstname the message is printed:
:theForm:theBlock:Section:firstName: Validation Error: Value is required.
which is wrong.
where as for user name the message is :
Username should be a valid email address.
which is what I want.
Any help would be greatly appreciated.
Thanks in advance.
It looks like this error message is being added in as a side effect of the required="true" attribute on the input field. When you submit the form, that validation will kick in before your controller gets a chance to check the field.
As you are validating this server side, do you need the required attribute on the inputfield?
All Answers
It looks like this error message is being added in as a side effect of the required="true" attribute on the input field. When you submit the form, that validation will kick in before your controller gets a chance to check the field.
As you are validating this server side, do you need the required attribute on the inputfield?
Have you tried making your isValidUsername as public method instead of private.
Thanks Bob. Your suggestion worked.
Thanks sRavu, however the isValidUserName is working fine, it's the firstName that's causing the issue.