I am using JSF 2.0 and RichFaces 4. For the date input, I am trying to force the pattern mm/dd/yyyy.
<h:inputText value="#{bean.startDate}">
<f:convertDateTime pattern="mm/dd/yyyy"/>
</h:inputText>
When user actually enters a date with a 2-digit year like so mm/dd/yy, then the converter automatically converts the year to 4 digits. This is undesired. How can I stop it from doing that without creating a custom converter? Is this a bug in the JSF converter?
This isn’t a bug. That’s just how
SimpleDateFormatworks. Here’s a cite of relevance from the linked javadoc:The JSF
<f:convertDateTime>is just using it under the covers. Your best bet is to extend theDateTimeConverterand validate the length of the submitted value before passing through to the realDateTimeConverter. You can’t go around creating a custom converter, but it’s after all fairly simple.Use it as follows:
Please note that I fixed the
mm(minutes) in the pattern to beMM(months).