+ Start a Discussion
VNVN 

How to avoid Validation Error in VF?

Hi,

 

I have created a visualforce page wherin a user can enter search data and click on search button. I have made three fields mandatory for the search. If a user doesnot enter value in any of the 3 mandatory field then an error message called validation error appears on screen as shown below.

 

Errors j_id0:j_id1:SearchInputs:j_id2:j_id3:j_id22: Validation Error: Value is required. j_id0:j_id1:SearchInputs:j_id2:j_id3:j_id27: Validation Error: Value is required.

 

 

Is it possible to avoid this error message and display some custom message?

Please help.

 

Thanks Priya

VisualForceVisualForce

Hi Priya...

       I think u are not used rerender attribute in command button component.. So that the whole page get refreshed and u get a error message..

        Use rerender attribute in Commandbutton component.. If this attribute also affect ur mandatory field use "immediate=true" attribute in Commandbutton tag..

pvassilievpvassiliev
Priya, did you get this resolved? We have the same problem.
TbomTbom

Hi, just came across this.. not sure if still an issue for you but you could have your validation in the page's controller and construct whatever kind of message you'd like.  Here's some snippets of something I did in a controller class for a similar case:

 

 

Boolean valid = true; String missing = ''; if(lead.FirstName == null || lead.FirstName == '' ){ valid = false; missing += ' [First Name] '; } ...(more code etc)... if(!valid){ ApexPages.Message theErrorMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Please provide: '+ missing ); ApexPages.addMessage( theErrorMsg ); return null; } else { upsert lead; return new PageReference('/successpage'); }