Calendar selection goes 1 day in the past

Components, Ajax Framework, Utilities and More.
Post Reply
jbx
Posts: 5
Joined: 12 Mar 2010, 18:42

12 Mar 2010, 18:49

I am encountering a wierd problem where the date I submit through the Calendar control goes back one day when I display it in the subsequent page. So I select 12th March 2010, and the date passed to the backing bean becomes 11th March 2010.

All I have is the following:

Code: Select all

@Stateless
@LocalBean
@Named
public class DateBean implements Serializable
{
    private Date date;

    public Date getDate()
    {
        return date;
    }

    public void setDate(Date date)
    {
        this.date = date;
    } 
}
and

Code: Select all

@Named
@SessionScoped
public class DateController implements Serializable
{
    @EJB
    private DateBean datebean;

    public String processDate()
    {        
        return "selectedDate";
    }
}
In the form page I have:

Code: Select all

     <h:form>
            <p:calendar value="#{dateBean.date}"  pattern="dd/MM/yyyy" />

        <h:commandButton value="Set Date" action="#{dateController.processDate}" />
        </h:form>
and in the result page named selectedDate.xhtml I have:

Code: Select all

The date you selected was: 
             <h:outputText value="#{dateBean.date}">
                <f:convertDateTime  pattern="dd/MM/yyyy" />
            </h:outputText>
I have also deployed the PrimeFaces showcase war file on my Glassfish v3 and the same problem also occurs. I select the date and submit, and the resultant date text becomes one day less than what I selected.

What could it be?

User avatar
optimus.prime
Prime
Posts: 17586
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

12 Mar 2010, 18:53

Are you sure the date passed is 1 day behind or the date display by outputText is behind. Can you log date on server side to see it.

Code: Select all

    public void setDate(Date date)
    {
        this.date = date; 
        System.out.println(date);
    } 

jbx
Posts: 5
Joined: 12 Mar 2010, 18:42

12 Mar 2010, 23:07

Hi,

I added that log.

I chose 12th March 2010.

The log said:
INFO: Fri Mar 12 00:00:00 CET 2010

The output text then said:
The date you selected was: 11/03/2010

As I said in my previous post, this problem is also happening with the PrimeFaces Showcase war deployed on the same Glassfish v3 server.

Could it be something related to timezones?

Thanks.

User avatar
optimus.prime
Prime
Posts: 17586
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

14 Mar 2010, 21:58

So the date passed is correct but h:outputText is displaying it as one day behind, defining a timezone on your f:convertDateTime should fix it. It is not a PrimeFaces problem.

See question 'I used the JSF DateTimeConverter to format an input field into a Date, but the dates were sometimes one day behind. Why?' at

http://ocpsoft.com/java/undocumented-jsf/

jbx
Posts: 5
Joined: 12 Mar 2010, 18:42

16 Mar 2010, 02:13

Yes that was the problem. Actually I found a more global way to set this to the system timezone, maybe its useful for other people looking for a solution to this problem.

Code: Select all

  <context-param>
    <param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name>
    <param-value>true</param-value>
</context-param>
I wonder why this property isn't set like this by default and overridden by the developer if required... but I guess otherwise life would be too easy. :(

User avatar
optimus.prime
Prime
Posts: 17586
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

16 Mar 2010, 13:29

I think it is because of backward compatibility as this is a JSF 2.0 only feature.

Post Reply
  • Information
  • Who is online

    Users browsing this forum: Baidu [Spider] and 8 guests