This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSF and the fly likes Custom validator error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Custom validator error" Watch "Custom validator error" New topic
Author

Custom validator error

Ravi Chilakapati
Greenhorn

Joined: Apr 20, 2010
Posts: 10
Hi.
I have a custom component which accepts a date input. And I want to support multiple date formats - DD/MM/YY; DD/MON/YY; DD/MON/YYYY; DD.MM.YYYY; DD.MM.YY and so on. You get the idea right? (MON indicates the first three letters of the name of the month).
But I was getting an error :
'01-04-2010' could not be understood as a date.
when I try to submit the page. I tried using immediate="true" to skip validation; I built my own custom validator but it is not even going into that one (after removing immediate="true" obviously).
Here is the skeleton of what I have here:

faces-config.xml


Validator:


XYZ.xhtml


So my problem is this:
Now after implementing my own validator, if I submit the page, I am still getting this ValidationException: '01-04-2010' could not be understood as a date.
Why is the framework not invoking my custom validator?

Thanks in advance.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15964
    
  19

I think that actually your problem is probably that the backing bean's property is a Date, but you're passing a String from the page, and it can't figure out how to convert it.

You may need a custom Converter.


Customer surveys are for companies who didn't pay proper attention to begin with.
Ravi Chilakapati
Greenhorn

Joined: Apr 20, 2010
Posts: 10
ahh.. that is the case Tim. Will try that out and let you know. Thanks.
Ravi Chilakapati
Greenhorn

Joined: Apr 20, 2010
Posts: 10
Thanks Tim. I built my own custom converter and now, I am able to support any date format that I want.

To others facing similar issues:
ISSUE: Unable to support multiple date formats.
ERROR EXAMPLE: '01-02-2004' could not be understood as date.
SOLUTION: Build your own custom converter (implement javax.faces.convert.Converter OR extend javax.faces.convert.DateTimeConverter) and your own custom validator (implement javax.faces.validator.Validator). Total of 3 functions that need to be implemented.

faces-config.xml


myPage.xhtml
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Custom validator error
 
Similar Threads
passing values from struts2 form to javascript
Wierd problem while using valueChangeListener() during submit of a form
<f:convertDateTime Problem
strange error for displaying date
JSP attendance management project error