| Author |
Validation messages - FacesMessages
|
Matt Couto
Ranch Hand
Joined: Jul 10, 2009
Posts: 38
|
|
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
Joined: Oct 28, 2009
Posts: 39
|
|
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 <h utpuMessage for="theparticularcomponentid" render="#{Mybean.willItRender}" />
|
...did you have the fish?!............................ No.
|
 |
Matt Couto
Ranch Hand
Joined: Jul 10, 2009
Posts: 38
|
|
That's what I'm used to do..
Thanks fellow!!
Anyone with any opinion is welcome!
|
 |
Samuel March
Ranch Hand
Joined: Oct 28, 2009
Posts: 39
|
|
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 h utputmessage 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 h utputmessage .
|
 |
Matt Couto
Ranch Hand
Joined: Jul 10, 2009
Posts: 38
|
|
I got it!!
Thanks again Samuel.
|
 |
 |
|
|
subject: Validation messages - FacesMessages
|
|
|