• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

To Authors - Exception Handling in JSF

 
S Mishra
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David,

Is there any way to add customised error messages when using Standard Converters and Validators in JSF. I actually have to use DateTimeConverter adn NumberConverter provided by JSF, but still it does not allow me to add customised error messages instead of Standard messages like Converter Exception or Validator Exception.

Although, JSF simplifies a great deal to create Custom Converters and Validators, still I have to create my own DateTime and NumberConverter and Validators just for simply displaying customised errors.

Moreover is there a way in JSF to handle our own Exception Handling as done in Struts so that we can throw Application level Exceptions instead of Standard Exceptions.

I am really looking for some useful inputs from you...


Thanks.
 
David Geary
Author
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can replace the standard error messages. You just supply a resource bundle with standard keys. See Changing the Text of Standard Error Messages on page 213 of Core JSF.

JSF does not provide anything like Strut's chained exceptions, but it would not be difficult to implement it.
 
S Mishra
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya David , you are correct we can do it in that way, but my requirements are to display the messages on a Pop up instead of displaying them on the JSP.

Moreover using messages like:
javax.faces.component.UIInput.CONVERSION=Please correct your input.

will do it for all Input Components and not for my component.

Say if I have to display a message like:

The Input date for "effectiveDate" is not entered in proper format MM/dd/yyyy.

where I will supply the effectiveDate and the format dynamically.

Can I do it in JSF?
 
Junilu Lacar
Bartender
Pie
Posts: 7465
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Looking for Ideas"

Welcome to JavaRanch! We have very few rules around here but one that we're kind of particular about is the JavaRanch Naming Policy. Please take a moment to review it and then change your profile real quick so that your publicly displayed name complies. We also don't want you to miss out on a chance to win the book in the week's promotion since only ranchers with valid names are eligible for the contest.

Thanks for your cooperation.
 
Varun Khanna
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, what we have done to overcome this is created a custom validator
and inside the validate method you can get the component Id of the component using the method : "component.getClientId()" and then pick up the message from the resource bundle corresponding to this id.

You can also pass the arguement (like format pattern etc.) to the properties file.


But I am not sure if this can be implemented in the Validator provided by JSF, I guess you need to create a custom one for yours.
 
S Mishra
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Varun,

But still can we do this through properties file where we can just identify the component id by using
<h:message for="amount"/> for id "amount" and getting the error message corresponding to this id from the properties file.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic