I have a Seam/JSF application that has a date field.
When the user types in 01.01.11, it interprets it to 01.01.0011 which is obviously incorrect. The correct value should have been 01.01.2011
Anyone encountered this? How did you solve it? The xhtml is the following:
<h:inputText value="#{budgetHandler.grantedFrom}">
<s:convertDateTime type="date" pattern="dd.MM.yyyy"/>
</h:inputText>
It’s not a Y2K problem. It’s just an user error. You asked the user to enter
dd.MM.yyyy, but the user entereddd.MM.yy. It’s just represented as last 2 digits of a 4-digit year. The same would happen if the user entered one or three digits as year.If you fix your pattern as
dd.MM.yy, you’ll see that it works fordd.MM.yyinput as you’d expect.A year of
11is then interpreted as2011, not1911. See, no Y2K problem.If you want to allow both date patterns, I’d suggest to create a custom converter which does the job rightly. You can find a kickoff example in my answer of this question: how to validate input date against multiple patterns?