Hi.
It's a "problem" of the DateTimeConverter. I patched the original one
and I'm using it as a custom converter now, that overrides the old one.
Dates can be _entered_ as 2- or 4-digits years but it will be _printed_
according to the pattern. Here is the patch I'm using currently. Some
hack, but works for me. Perhaps someone finds it useful, too.
--cut here--
Index:
myfaces-current/api/api/src/main/java/javax/faces/convert/DateTimeConverter.java
===================================================================
---
myfaces-current/api/api/src/main/java/javax/faces/convert/DateTimeConverter.java
(revision 369026)
+++
myfaces-current/api/api/src/main/java/javax/faces/convert/DateTimeConverter.java
(working copy)
@@ -21,6 +21,8 @@
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
@@ -79,7 +81,46 @@
format.setTimeZone( tz );
try
{
- return format.parse(value);
+ // format as usual
+ Date lDate = format.parse(value);
+
+ // if a 2-digit year was entered in a 4-digit "pattern",
+ // try to add century
+
+ // check if it's 4-digit format:
+ // is a pattern (=simpledateformat) or medium
(=dateformat) style used?
+ if ( (_pattern != null && _pattern.indexOf("yyyy") >
-1) ||
+ (getDateStyle().equals(STYLE_DEFAULT) ||
getDateStyle().equals(STYLE_MEDIUM)) ) {
+
+ // prepare calendar instance
+ Calendar lCal = Calendar.getInstance();
+ lCal.setTime(lDate);
+
+ // check if the year is 2-digit year, although
pattern is set to 4-digit
+ if (lCal.get(Calendar.YEAR) < 100) {
+
+ // do the simpledateformat handling
+ if (_pattern != null) {
+
+ // format it as a 2-digit year,
which supports the
century mechanism
+ ((SimpleDateFormat)
format).applyPattern(_pattern.replace("yyyy","yy"));
+ lDate = format.parse(value);
+ } else {
+
+ // format it as a 2-digit year,
which supports the
century mechanism
+ _dateStyle = STYLE_SHORT;
+
+ format = getDateFormat();
+
+ if( tz != null )
+ format.setTimeZone( tz );
+
+ lDate = format.parse(value);
+ }
+ }
+ }
+
+ return lDate;
}
catch (ParseException e)
{
-- cut here--
regards,
Veit
Martin Marinschek schrieb:
> But <f:convertDateTime>
>
> just uses the standard Java-date functionality, so this should work.
>
> What happens if you use a text-field, and apply a converter to this
> text-field?
>
> regards,
>
> Martin
>
> On 1/14/06, Veit Guna <[EMAIL PROTECTED]> wrote:
>> Hi.
>>
>> I've updated all my faces libs to 1.1.2-SNAPSHOT. But the problem still
>> exists.
>> Some improvements were made to the inputCalendar component. 01.01.30
>> entered in the textfield will be correctly interpreted as 1930 by the
>> inputCalendar component when it popups. In the old release, it
>> interpreted it as the year 30.
>>
>> So, it seems convertDateTime still lacks the 01.01.30 -> 01.01.1930
>> support :(.
>>
>> regards,
>> Veit
>>
>>
>> Martin Marinschek schrieb:
>>> There have been many changes in the inputCalendar component since the
>>> 1.1.1 version - you'll need to update to a recent version for support
>>> of the inputCalendar... I do suppose that your issue is fixed already,
>>> though.
>>>
>>> regards,
>>>
>>> Martin
>>>
>>> On 1/14/06, Veit Guna <[EMAIL PROTECTED]> wrote:
>>>> Hi.
>>>>
>>>> I'm using Myfaces 1.1.1 with the Tomahawk extension. Now I would like to
>>>> let the user enter his birthdate in the format dd.MM.yyyy (german
>>>> format). I use this on my page:
>>>>
>>>> --cut here--
>>>> ...
>>>> ...
>>>> ...
>>>>
>>>> <t:inputCalendar id="birthdate" value="#{registrationPerson.birthdate}"
>>>> required="true" renderAsPopup="true" renderPopupButtonAsImage="true"
>>>> popupTodayString="#{msg.calendar_popup_today_label}"
>>>> popupWeekString="#{msg.calendar_popup_week_label}"
>>>> popupGotoString="#{msg.calendar_popup_actual_month_label}"
>>>> popupDateFormat="dd.MM.yyyy">
>>>>
>>>> <f:convertDateTime pattern="dd.MM.yyyy" type="date" />
>>>>
>>>> </t:inputCalendar>
>>>> ...
>>>> ...
>>>> ...
>>>> --cut here--
>>>>
>>>> Entering in the format 01.01.1976 works ok. Also the popup uses this
>>>> format. But when entering 01.01.76, it is interpreted (and redisplayed
>>>> when validation errors occur on this page) as 01.01.0076. Is this by
>>>> design or a bug? So is it possible, to let the user enter either 76 or
>>>> 1976 an display and interpret it as 1976? Or do I have to implement this
>>>> in a custom converter (perhaps extending the "normal" one)?
>>>>
>>>> I know, entering 01.01.10 could mean 2010 OR 1910 in this particular
>>>> (birthdate) case - but one could pass the marginal value as parameter to
>>>> the converter (<10 means 2000, >10 means 1900).
>>>>
>>>> regards,
>>>> Veit
>>>>
>>
>
>
> --
>
> http://www.irian.at
>
> Your JSF powerhouse -
> JSF Consulting, Development and
> Courses in English and German
>
> Professional Support for Apache MyFaces
>
>