Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Validation messages - FacesMessages  RSS feed

 
Matt Couto
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks,
I've got a doubt about showing validation messages to the user. When validating some business should i throw an exception or just put some condition and use facesMessages to show it on the page instead?
tia
 
Samuel March
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Personally i think exceptions are extravagent. Just set a boolean for the component for it's render= attribute.
If the component is found unvalid make the boolean custom reference variable for it "true"(true to render).
If its valid make it false.
But if memory serves me correctly it's only required to have the for= part bound to the component.
with the faces context and the component reference, while you are in the validator method you can bind/queue a message addMessage()
onto the component through the facescontext.


Don't forget to bind an <hutpuMessage for="theparticularcomponentid" render="#{Mybean.willItRender}" />
 
Matt Couto
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's what I'm used to do..
Thanks fellow!!

Anyone with any opinion is welcome!
 
Samuel March
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you throw an exception , i believe you get a stack trace, so you need to clear the "java" error log, not just handle it and take what you want in either "summary" or "the full report".
If you use SAX or DOM with Xerces , the process of document validation is handled the same way for the point, so you can grab a complete stack trace that is logged. Though you can probably switch off logging for that component or section relating the Exception if you want and that would make that more sensible for using an exception.

Just thought i'd add this since my last post was a bit rough in its explaination:
But if memory serves me correctly it's only required to have the for= part bound to the component.

When a component is validated in a validator, if it is set unvalid and an hutputmessage is associated to the components id by a for="thevalidatedcomponentsID" , the error message queued on the component will show , there is no need to change the render attribute of the hutputmessage .
 
Matt Couto
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it!!
Thanks again Samuel.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!