File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » JSF
Bookmark "Custom validator error" Watch "Custom validator error" New topic

Custom validator error

Ravi Chilakapati

Joined: Apr 20, 2010
Posts: 10
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:




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: 17417

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.

An IDE is no substitute for an Intelligent Developer.
Ravi Chilakapati

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

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.


I agree. Here's the link:
subject: Custom validator error
It's not a secret anymore!