3

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

Mathew Rock
  • 989
  • 2
  • 14
  • 32
  • try adding javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONEtrue – Pritesh Shah Jun 24 '13 at 09:16
  • I had that param in web.xml. – Mathew Rock Jun 24 '13 at 09:30
  • 1
    @PriteshShah: sorry, but this is complete nonsense. The OP is attempting to explicitly set `timeZone` attribute which would always override the default. – BalusC Jun 24 '13 at 12:38
  • Matthew, I have the impression that you have left out one rather crucial part from the question. The code posted so far works namely perfectly fine when placed in a completely blank `` (which is what everyone expects from you when seeing JSF code snippets). However, you've in your real code most likely *actually* placed it inside an `` or `` with a `var="bb"`. That detail should absolutely not be omitted from the question in such way that the problem can't be reproduced anymore by copypasting the code into a blank ``. – BalusC Jun 24 '13 at 12:40
  • BalusC, It´s inside ** p:datatable ** adn bb are backingBean. Thaks for help me you are The Master Chief of JSF. – Mathew Rock Jun 25 '13 at 06:18
  • 1
    Exactly as I guessed. Now, your problem is already answered in http://stackoverflow.com/questions/7530560/how-to-set-converter-properties-for-each-row-of-a-datatable/ and http://stackoverflow.com/questions/7122460/jsf-convertdatetime-with-timezone-in-datatable/ – BalusC Jun 25 '13 at 11:36

2 Answers2

1

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.

samael
  • 2,007
  • 1
  • 16
  • 34
0

Use <f:ajax/> to change the time. Add following code on your xhtml.

        <p>
            <h:selectOneMenu value="#{bb.zone}">
                <f:selectItems value="#{bb.timeZones}"/>
                <f:ajax execute="@this" listener="#{bb.changeZone()}" render="hour"/>
            </h:selectOneMenu>
        </p>
        <p>
            <h:outputText id="hour" value="#{bb.hour}">
                <f:convertDateTime pattern="HH:mm" timeZone="#{bb.zone}" />
            </h:outputText>
        </p>

And, add following code in your managed bean

    private Date hour=new Date();
    private String zone;
    private List<String> timeZones=new ArrayList<String>();
    public Bean() {
        timeZones= Arrays.asList( TimeZone.getAvailableIDs());
    }

    public void changeZone(){
    System.out.println("Time Zone : "+ zone);
    }
Masudul
  • 21,823
  • 5
  • 43
  • 58