In my jsf application I know how to validate user input against one pattern in my ice:selectInputDate using a jsf converter:
<f:convertDateTime pattern="MM/dd/yyyy" />
but how should I do if I want to let the user be able to enter a date in format: “MM-dd-yyyy” too?
I think this can be done extending DateConverter from jsf but I already tried with that and I fail. Do you have a valid example to validate input date against multiple patterns?
Thanks.
UPDATE: I’m using jsf 1.2
Create a custom converter which accepts multiple patterns by
<f:attribute>on the component.Here’s how you’d like to have the view to look like:
And here’s how the converter can look like (for JSF 1.x, register it as
in
faces-config.xmlinstead)Note that it only picks the first (default) pattern to redisplay the value. So in the above example, if you enter
05-10-2011, then it get redisplayed as05/10/2011.Unrelated to the concrete problem, the pattern
MM-dd-yyyyisn’t very common. Didn’t you mean to usedd-MM-yyyy?