Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

display error message

 
piers morgan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am new to JSF and trying to figure out a way to display a message in a jsf page. Once the submit button is clicked the action method performs validation. The next step is to go back to the same page with an error message showing what went wrong. Any help would be greatly appreciated!

Thanks in advance!
Piers
 
Tim Holloway
Bartender
Posts: 18419
60
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Piers!

There are 2 message-display JSF tags, One is for a single control (message for="ctlId") and the other is for messages in general (<h:messages>). To add your own custom messages, you can obtain the FacesContext in your action processor, create a Faces Message object, and add it to the FacesContext messages collection using JSF API calls.

JSF's built-in validation framework will run before the action processor is invoked. Items which fail built-in validators will be flagged with error messages and the action processor won't be invoked, so if you're adding "second-stage" validation in the action processor, it will only be run if the primary validations all succeed.
 
piers morgan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help Tim! I was able to display messages using the solution you mentioned.

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!