1

I have the next Java model bean (which contains not only a date in milliseconds but also a time zone)

public class Device {

    private Calendar lentDate;

    // getters and setters
}

and the next xhtml page fragment

<rich:dataTable value="#{tagBean.devices}" var="device">
    <rich:column>
        <h:outputText value="#{device.lentDate.time}">
            <f:convertDateTime pattern="dd.MM.yyyy" timeZone="#{device.lentDate.timeZone}"/>
        </h:outputText>
    </rich:column>
</rich:dataTable>

But the timeZone attribute does not get the device.lentDate.timeZone value. Looks like it is because when the f:convertDateTime tag is rendered, the device variable is not available yet.

Is it possible to force JSF to render the f:convertDateTime tag after the device variable is available? Or the only way to make the timeZone set properly for each device in this case is to create a custom date/time converter?

Thank you.

yaskovdev
  • 1,213
  • 1
  • 12
  • 22
  • You can create function in your backing bean with parameter _device_ which return date based on timeZone. And use this function in `h:outputText`. – Vasil Lukach Feb 23 '14 at 20:11

1 Answers1

1

The problem is that the attributes of the converter are evaluated when the view is build. This is partially because a converter is not a component itself, but in Facelets implemented by a TagHandler that sets a converter instance in the parent component. See JSTL in JSF2 Facelets... makes sense? for a very thorough background explanation.

You can solve this by using the <o:converter> from OmniFaces that was specifically build for this use case. Contrary to the regular converters, this one does evaluate its attributes when its parent component is being rendered.

See: http://showcase.omnifaces.org/taghandlers/converter

Community
  • 1
  • 1
Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140