Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update timeZone f:convertDateTime

When I change timeZone of f:convertDateTime this doesn´t change.

`<p:dataTable id="tabla2" value="#{bb.dataTable}" var="trm" resizableColumns="true"
    style="width : 1400px" editable="true" editMode="cell"
    rowStyleClass="#{styleController.daColoresParaEstadoTramos(trm, bb.fechaInicio)}"><p:column>
        <p:cellEditor>
            <f:facet name="output">
                <h:outputText value="#{trm.tramo.horaDespeguePrevista}">
                    <f:convertDateTime pattern="HH:mm" timeZone="#{bb.zonaH}" />
                </h:outputText>
            </f:facet>  
            <f:facet name="input">
                <p:inputMask value="#{trm.tramo.horaDespeguePrevista}" mask="99:99" >
                    <f:convertDateTime pattern="HH:mm" timeZone="#{bb.zona}" />
                </p:inputMask>
            </f:facet>
        </p:cellEditor>         
    </p:column></p:dataTable>`

zone is a element java.util.TimeZone. I use primefaces 3.5

like image 949
Mathew Rock Avatar asked May 01 '26 01:05

Mathew Rock


1 Answers

I've just solved a similar problem on my app. The issue is with the JSF lifecycle. Like you I was taking a collection of objects and using f:convertDateTime for a Date on each, using a timezone value (I'm showing bookings for various locations around the world).

Setting a breakpoint in the getter for my list of bookings and another in the ConvertDateTimeHandler I could see that JSF was tring to convert the date before I had even got the bookings from the backing bean.

I was using a ui:repeat and was able to resolve the issue by switching to using c:forEach from JSTL.

You may be able to do something similar if you don't have to have the Primefaces datatable. Otherwise you may be better off having a transient getter which returns a String of the date already formatted for the timezone in question.

A quick way to prove this would be to get the first object in your collection and put it through an h:outputText along with the f:convertDateTime. If it converts correctly then try an alternative to datatable.

like image 77
samael Avatar answered May 02 '26 14:05

samael