• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Custom validator error

 
Ravi Chilakapati
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ravi Chilakapati
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ahh.. that is the case Tim. Will try that out and let you know. Thanks.
 
Ravi Chilakapati
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic