Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

convertDateTime: caching TimeZone: possible JSF bug?

843842Mar 28 2006 — edited Mar 31 2006
Hi all,

I'm outputing a date field utilizing the timezone attribute of the convertDateTime tag. When I change the viewing timezone, the convertDateTime tag seems to be caching the old timezone value.

Is anyone else encountering this issue? Is it a Bug? Is there a work around?

Thanks all,


Here is some test code I wrote to expose the bug...
public class TimeZoneTest {
    private static final Log LOGGER = LogFactory.getLog(TimeZoneTest.class);

    private TimeZone timeZone = TimeZone.getTimeZone("GMT");
    private Date currentTime = new Date();
    private SelectItem[] availableTimeZones;

    public TimeZone getTimeZone() {
        return timeZone;
    }

    public void setTimeZone(String timeZone) {
        this.timeZone = TimeZone.getTimeZone(timeZone);
    }

    public Date getCurrentTime() {
        return currentTime;
    }

    public SelectItem[] getAvailableTimeZones() {
        if (null == availableTimeZones) {
            availableTimeZones = new SelectItem[3];
            availableTimeZones[0] = new SelectItem("GMT","GMT");
            availableTimeZones[1] = new SelectItem("PST","PST");
            availableTimeZones[2] = new SelectItem("EST","EST");

        }
        return availableTimeZones;
    }

}
The JSP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html" %>

<META HTTP-EQUIV="Pragma" CONTENT="no-cache"/>
<META HTTP-EQUIV="Expires" CONTENT="-1"/>
<f:view>
    <html xmlns="http://www.w3.org/1999/xhtml">
        <body>
            <h:form>
                <h:panelGrid columns="2">
                    <h:outputText value="TimeZone:"/>
                    <h:outputText value="#{timeZoneTest.timeZone.ID}"/>
                    <h:outputText value="Current Time:"/>
                    <h:outputText value="#{timeZoneTest.currentTime}">
                        <f:convertDateTime pattern="MM/dd/yyyy HH:mm:ss z" timeZone="#{timeZoneTest.timeZone}"/>
                    </h:outputText>
                    <h:outputText value="Change Time Zone:"/>
                    <h:selectOneMenu value="#{timeZoneTest.timeZone.ID}"
                                     onchange="submit()">
                        <f:selectItems value="#{timeZoneTest.availableTimeZones}"/>
                    </h:selectOneMenu>
                </h:panelGrid>
            </h:form>
        </body>
    </html>
</f:view>
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 28 2006
Added on Mar 28 2006
7 comments
450 views