3
votes

While specifiing the timezone as a string literal works flawless:

<h:outputText value="#{item.dateChange}">
    <f:convertDateTime pattern="dd.MM.yyyy HH:mm" timeZone="Europe/Berlin"/>
</h:outputText>

Providing the value by bean doesn't work (Timeoffset 1h to UTC and daylight saving 1h are not applied)

<h:outputText value="#{item.dateChange}">
    <f:convertDateTime pattern="dd.MM.yyyy HH:mm" timeZone="#{item.platform.timeZone}"/>
</h:outputText>

I tried both of the methods below none of them works:

public TimeZone getTimeZone() {
    return TimeZone.getTimeZone("Europe/Berlin");
}

public String getTimeZone() {
    return "Europe/Berlin";
}

I need the timezone to be configurable for a user, how can this be achieved?

EDIT: In order to make sure that the timezone object is available:

 <h:outputText value="#{item.platform.timeZone}"/> 

sun.util.calendar.ZoneInfo[id="Europe/Berlin",offset=3600000,dstSavings=3600000,useDaylight=true,transitions=143,lastRule=java.util.SimpleTimeZone[id=Europe/Berlin,offset=3600000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDayOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=3600000,endTimeMode=2]]

or simply: "Europe/Berlin" in the 2nd attempt.

1
Just to be sure this is not something silly: what you do see when you h:outputText that #{item.platform.timeZone} property?Gimby
@Gimby either the very long toString of a TimeZone object or the String "Europe/Berlin" in the later version. For me it seems that the expression language doesn't work on this attribute, I've no idea what could be special with this.stacker
This thread may be relevant to you: stackoverflow.com/questions/7122460/…Gimby
I wonder how the source of the Item bean looks like. Please post the source code. I've setup a sample project using the time zone from the bean. It works for me, when I use a simple getter within that bean.Spindizzy
@Gimby Thank you! A customConverter as adviced by BalusC solved the issue, you could add this as an answer.stacker

1 Answers

1
votes

As pointed out by Gimby a similiar question has already be answered by BalusC

Due to restrictions in the f: tags a customConverter is required.

A detailed description of the issue and a sample implementation by BalsuC is available here: JSF convertDateTime with timezone in datatable

Note: The converter provided there expects the bean to return a string describing the timeZone and not the TimeZone object.