• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Validation messages - FacesMessages

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 <h:outpuMessage for="theparticularcomponentid" render="#{Mybean.willItRender}" />
 
Matt Couto
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 h:outputmessage 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:outputmessage .
 
Matt Couto
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got it!!
Thanks again Samuel.
 
If I had asked people what they wanted, they would have said faster horses - Ford. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic