As my boss would always say it, "programmers are lazy". That sentence has a certain truth to it. As a programmer, I came to rely on certain framework and their respective built-in components. But there's no perfection to anything in this world and my latest struggle with JSF Richfaces involve the user of <rich:calender>
<rich:calendar> is a good visual component for date functions. It allows for both manual and visual input and can specify date format among other features. It allows automatically data conversion to any date style that you specified. However, there is a problem to it; if you specify date style to be "MM/dd/yyyy" format and you enter "08/22/88", the date is converted to 08/22/0088. I believe that is the inherent problem with JSF <f:converDateTime> tag.
The work around I implemented was I used a date validator. (I guess you can try to write a custom date converter but it'll be much more complicated and I was not willing to spend more time on this matter as I had other bugs and features to work on.) Essentially what the date validator does is it will display error message if you enter 08/22/88. First the calendar component will convert it to 08/22/0088 and it'll be validated against my custom date validator. Since I do not allow years to be started with anything other than 18, 19 or 20s, the validator will throw an exception.
The use of validator is pretty straight forward. You will have to declare you validator in your face-config.xml file and then you can call it using <f:validator> The only thing I think important is that I used Java' Pattern and Regular Expression classes for validation.
No comments:
Post a Comment