This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Struts and the fly likes To Authors - Exception Handling in JSF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "To Authors - Exception Handling in JSF" Watch "To Authors - Exception Handling in JSF" New topic

To Authors - Exception Handling in JSF

S Mishra

Joined: Dec 14, 2004
Posts: 15
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 in Advance,<br /> <br />SM
David Geary
Ranch Hand

Joined: Apr 23, 2003
Posts: 45
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.

David Geary Sabreware, Inc<br /><a href="" target="_blank" rel="nofollow"></a><br /> <br />Author: Graphic Java Series, Advanced JavaServerPages, Core JSTL and Core JavaServer Faces
S Mishra

Joined: Dec 14, 2004
Posts: 15
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

Joined: Feb 26, 2001
Posts: 6529

"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.

Junilu - [How to Ask Questions] [How to Answer Questions]
Varun Khanna
Ranch Hand

Joined: May 30, 2002
Posts: 1400
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.

- Varun
S Mishra

Joined: Dec 14, 2004
Posts: 15
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.
I agree. Here's the link:
subject: To Authors - Exception Handling in JSF
It's not a secret anymore!