You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Matthias Kahlau <mk...@web.de> on 2006/03/20 16:34:53 UTC

inputCalendar problem

Hi!


I have a date "18.3.2006" shown in an outputText with a nested
convertDateTime with timeZone="Europe/Berlin". If I open an edit form with
this date "18.3.2006", the date is shown in an inputCalendar, also with a
nested convertDateTime with timeZone="Europe/Berlin".

The problem is that the date is then shown as "19.3.2006". Does the
inputCalendar convert the date itself to another TimeZone?

Thanks.


-Matthias



Re: inputCalendar problem

Posted by Martin Marinschek <ma...@gmail.com>.
if you use the s:convertDateTime converter, you're fine.

regards,

Martin

On 3/21/06, Frank Felix Debatin <ff...@gmx.net> wrote:
> Hi Matthias,
>
> actually I'm using the ADF calendar component - in the way described below,
>
> The calendar class picks up the CET locale ... but I'm not sure how and why.
>
>
> Frank Felix
>
>         <af:selectInputDate
>                 label="#{bundle['...']}"
>               value="#{bean.date}"
>                 chooseId="validFrom" required="true">
>                 <af:convertDateTime/>
>         </af:selectInputDate>
>
> class Bean
> {
>         Calendar myDate = ...
>
>         public Date getDate()
>         {
>                 return toNormalizedDate(myDate);
>         }
>
>         public void setDate(Date date)
>         {
>                 myDate = fromNormalizedDate(date);
>         }
> }
>
> -----Original Message-----
> From: mkahlau@web.de [mailto:mkahlau@web.de]
> Sent: Tuesday, March 21, 2006 6:16 PM
> To: MyFaces Discussion
> Subject: AW: inputCalendar problem
>
>
> > Hi Matthias,
> >
> > I use the methods below to convert back and forth.
> >
> > Because our app uses java.util.Calendar, the method "toNormalizedDate"
> > is used to convert the calendar to a date suitable for JSF, and
> > "fromNormalizedDate" to convert it back.
>
> Many thanks. So you don't use the convertDateTime action at all? And how do
> I switch to using the Europe/Berlin TimeZone?
>
> -Matthias
>
>
> > Frank Felix
> >
> >       /**
> >        * Required to work around a bug in ADF/JSF, where
> >        * dates are always normalized to GMT, and then time
> >        * is set to 0, resulting in a change of date for all
> >        * time zones before GMT.
> >        *
> >        * @param calendar
> >        * @return normalized date
> >        */
> >       @SuppressWarnings("deprecation")
> >       public static Date toNormalizedDate(Calendar calendar)
> >       {
> >               return calendar==null ? null : new Date(
> >                       Date.UTC(
> >                               calendar.get(Calendar.YEAR)-1900,
> >                               calendar.get(Calendar.MONTH),
> >                               calendar.get(Calendar.DATE),
> >                               0,
> >                               0,
> >                               0
> >                       )
> >               );
> >       }
> >
> >       /**
> >        * Required to work around a bug in ADF/JSF, where
> >        * dates are always normalized to GMT, and then time
> >        * is set to 0, resulting in a change of date for all
> >        * time zones before GMT.
> >        *
> >        * @param date the date to copy from
> >        */
> >       @SuppressWarnings("deprecation")
> >       public static Calendar fromNormalizedDate(Date date)
> >       {
> >               if (date==null)
> >               {
> >                       return null;
> >               }
> >               return new GregorianCalendar(
> >                       date.getDate(),
> >                       date.getYear()+1900),
> >                       date.getMonth()
> >               );
> >       }
> >
>
>


--

http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces

RE: inputCalendar problem

Posted by Frank Felix Debatin <ff...@gmx.net>.
Hi Matthias, 

actually I'm using the ADF calendar component - in the way described below, 

The calendar class picks up the CET locale ... but I'm not sure how and why.


Frank Felix

	<af:selectInputDate
		label="#{bundle['...']}"
	      value="#{bean.date}"
		chooseId="validFrom" required="true">
		<af:convertDateTime/>
	</af:selectInputDate>

class Bean 
{
	Calendar myDate = ...

	public Date getDate()
	{
		return toNormalizedDate(myDate);
	}
	
	public void setDate(Date date)
	{
		myDate = fromNormalizedDate(date);		
	}
}

-----Original Message-----
From: mkahlau@web.de [mailto:mkahlau@web.de] 
Sent: Tuesday, March 21, 2006 6:16 PM
To: MyFaces Discussion
Subject: AW: inputCalendar problem


> Hi Matthias,
>
> I use the methods below to convert back and forth.
>
> Because our app uses java.util.Calendar, the method "toNormalizedDate" 
> is used to convert the calendar to a date suitable for JSF, and 
> "fromNormalizedDate" to convert it back.

Many thanks. So you don't use the convertDateTime action at all? And how do
I switch to using the Europe/Berlin TimeZone?

-Matthias


> Frank Felix
>
> 	/**
> 	 * Required to work around a bug in ADF/JSF, where
> 	 * dates are always normalized to GMT, and then time
> 	 * is set to 0, resulting in a change of date for all
> 	 * time zones before GMT.
> 	 *
> 	 * @param calendar
> 	 * @return normalized date
> 	 */
> 	@SuppressWarnings("deprecation")
> 	public static Date toNormalizedDate(Calendar calendar)
> 	{
> 		return calendar==null ? null : new Date(
> 			Date.UTC(
> 				calendar.get(Calendar.YEAR)-1900,
> 				calendar.get(Calendar.MONTH),
> 				calendar.get(Calendar.DATE),
> 				0,
> 				0,
> 				0
> 			)
> 		);
> 	}
>
> 	/**
> 	 * Required to work around a bug in ADF/JSF, where
> 	 * dates are always normalized to GMT, and then time
> 	 * is set to 0, resulting in a change of date for all
> 	 * time zones before GMT.
> 	 *
> 	 * @param date the date to copy from
> 	 */
> 	@SuppressWarnings("deprecation")
> 	public static Calendar fromNormalizedDate(Date date)
> 	{
> 		if (date==null)
> 		{
> 			return null;
> 		}
> 		return new GregorianCalendar(
> 			date.getDate(),
> 			date.getYear()+1900),
> 			date.getMonth()
> 		);
> 	}
>


AW: inputCalendar problem

Posted by Matthias Kahlau <mk...@web.de>.
> Hi Matthias,
>
> I use the methods below to convert back and forth.
>
> Because our app uses java.util.Calendar, the method "toNormalizedDate" is
> used to convert the calendar to a date suitable for JSF, and
> "fromNormalizedDate" to convert it back.

Many thanks. So you don't use the convertDateTime action at all? And how do
I switch to using the Europe/Berlin TimeZone?

-Matthias


> Frank Felix
>
> 	/**
> 	 * Required to work around a bug in ADF/JSF, where
> 	 * dates are always normalized to GMT, and then time
> 	 * is set to 0, resulting in a change of date for all
> 	 * time zones before GMT.
> 	 *
> 	 * @param calendar
> 	 * @return normalized date
> 	 */
> 	@SuppressWarnings("deprecation")
> 	public static Date toNormalizedDate(Calendar calendar)
> 	{
> 		return calendar==null ? null : new Date(
> 			Date.UTC(
> 				calendar.get(Calendar.YEAR)-1900,
> 				calendar.get(Calendar.MONTH),
> 				calendar.get(Calendar.DATE),
> 				0,
> 				0,
> 				0
> 			)
> 		);
> 	}
>
> 	/**
> 	 * Required to work around a bug in ADF/JSF, where
> 	 * dates are always normalized to GMT, and then time
> 	 * is set to 0, resulting in a change of date for all
> 	 * time zones before GMT.
> 	 *
> 	 * @param date the date to copy from
> 	 */
> 	@SuppressWarnings("deprecation")
> 	public static Calendar fromNormalizedDate(Date date)
> 	{
> 		if (date==null)
> 		{
> 			return null;
> 		}
> 		return new GregorianCalendar(
> 			date.getDate(),
> 			date.getYear()+1900),
> 			date.getMonth()
> 		);
> 	}
>


RE: inputCalendar problem

Posted by Frank Felix Debatin <ff...@gmx.net>.
Hi Matthias, 

I use the methods below to convert back and forth. 

Because our app uses java.util.Calendar, the method "toNormalizedDate" is
used to convert the calendar to a date suitable for JSF, and
"fromNormalizedDate" to convert it back. 

Frank Felix

	/**
	 * Required to work around a bug in ADF/JSF, where
	 * dates are always normalized to GMT, and then time
	 * is set to 0, resulting in a change of date for all
	 * time zones before GMT.   
	 * 
	 * @param calendar
	 * @return normalized date
	 */
	@SuppressWarnings("deprecation")
	public static Date toNormalizedDate(Calendar calendar)
	{
		return calendar==null ? null : new Date(
			Date.UTC(
				calendar.get(Calendar.YEAR)-1900,
				calendar.get(Calendar.MONTH),
				calendar.get(Calendar.DATE),
				0,
				0,
				0
			)
		);
	}

	/**
	 * Required to work around a bug in ADF/JSF, where
	 * dates are always normalized to GMT, and then time
	 * is set to 0, resulting in a change of date for all
	 * time zones before GMT.    
	 * 
	 * @param date the date to copy from 
	 */
	@SuppressWarnings("deprecation")
	public static Calendar fromNormalizedDate(Date date)
	{
		if (date==null)
		{
			return null;
		}
		return new GregorianCalendar(
			date.getDate(),
			date.getYear()+1900),
			date.getMonth()
		);
	}


AW: inputCalendar problem

Posted by Matthias Kahlau <mk...@web.de>.
> Hi Matthias,
>
> I believe this is the dreaded converter timezone problem which can be
> fixed by using your own special converter.
>
> What I generally do is put a component-binding on the calendar
> component and then create the component in the backend, and there I
> set stuff which is repeatable across the whole app (like a
> converter="#{converterBean.converter}") and styles.

Thanks. This sounds a little bit complicated for the apparently small
problem.

How does this converter have to look like? Can't I use the convertDateTime
standard action?

-Matthias

> regards,
>
> Martin
>
> On 3/20/06, Matthias Kahlau <mk...@web.de> wrote:
> > Hi!
> >
> >
> > I have a date "18.3.2006" shown in an outputText with a nested
> > convertDateTime with timeZone="Europe/Berlin". If I open an
> edit form with
> > this date "18.3.2006", the date is shown in an inputCalendar,
> also with a
> > nested convertDateTime with timeZone="Europe/Berlin".
> >
> > The problem is that the date is then shown as "19.3.2006". Does the
> > inputCalendar convert the date itself to another TimeZone?
> >
> > Thanks.
> >
> >
> > -Matthias
> >
> >
> >
>
>
> --
>
> http://www.irian.at
>
> Your JSF powerhouse -
> JSF Consulting, Development and
> Courses in English and German
>
> Professional Support for Apache MyFaces


Re: inputCalendar problem

Posted by Martin Marinschek <ma...@gmail.com>.
Hi Matthias,

I believe this is the dreaded converter timezone problem which can be
fixed by using your own special converter.

What I generally do is put a component-binding on the calendar
component and then create the component in the backend, and there I
set stuff which is repeatable across the whole app (like a
converter="#{converterBean.converter}") and styles.

regards,

Martin

On 3/20/06, Matthias Kahlau <mk...@web.de> wrote:
> Hi!
>
>
> I have a date "18.3.2006" shown in an outputText with a nested
> convertDateTime with timeZone="Europe/Berlin". If I open an edit form with
> this date "18.3.2006", the date is shown in an inputCalendar, also with a
> nested convertDateTime with timeZone="Europe/Berlin".
>
> The problem is that the date is then shown as "19.3.2006". Does the
> inputCalendar convert the date itself to another TimeZone?
>
> Thanks.
>
>
> -Matthias
>
>
>


--

http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces