jsf 2 - JSR303 ConstraintValidator, how to show the message without an error page -


im working jsf 2.0 , glassfish v3. testing functionality of jsr303 bean validation, created validator implements constraintvalidator , annotate on property wich want validate.

it works fine, displays glassfish default error page. don't want displayed, rather have message displayed in <h:outputtext> or something.

does know how achieve this?

here validator method:

@override public boolean isvalid(string searcharg, constraintvalidatorcontext ctx) {      boolean searchargcorrect = true;     facesmessage msg;     if(searcharg!=null) {         ctx.disabledefaultconstraintviolation();         if(searcharg.length() < 3) {             ctx.buildconstraintviolationwithtemplate("searcharg short").addconstraintviolation();             searchargcorrect=false;              msg = new facesmessage(                     facesmessage.severity_error,                     "searcharg short", null);              throw new  validatorexception(msg);         }     }      return searchargcorrect; } 

ps: know there easier ways validate length of string, above code snippet demo/testing purposes. have plans validator.

you're mixing 2 concepts: jsf validation , jsr 303 bean validation. you're implementing jsr303 bean validation, you're throwing jsf-specific validatorexception.

the method should not throw exception. method should return true or false depending on validation outcome. message has definied in validationmessages.properties. jsf display in <h:message> associated input component.

see this documentation on creating custom constraints message.


or if you're actually after standard jsf validator, should implementing javax.faces.validator.validator instead, annotate @facesvalidator , declare in view <f:validator>. can throw validatorexception , message displayed in <h:message> associated input component.


Comments

Popular posts from this blog

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

apache - Add omitted ? to URLs -

php - How can I stop spam on my custom forum/blog? -