Вопрос

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.

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top