This week's giveaway is in the Java in General forum.
We're giving away four copies of Java Challengers and have Rafael del Nero on-line!
See this thread for details.
Win a copy of Java Challengers this week in the Java in General forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

To Authors - Exception Handling in JSF

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 16146
269
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic