Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Unfortunately, that's the nature of <code>&lt;f:xxx&gt;</code> tags. When the view is to be built, a single instance of the tag is been built where the converter is instantiated. All of its attribtues are been read and set only once. At the moment the view is been built, the <code>#{item}</code> resolves to <code>null</code> (it's only available during rendering of the view), so the <code>timeZone</code> attribute will be <code>null</code> and then default to UTC. When the view is to be rendered, the very same converter instance is been reused for each row of the table.</p> <p>There are several ways to solve this. I can think of a custom converter or an EL function. I think a custom converter is after all the best as it can then also be reused in input components. The following kickoff example should work out for you (nullchecks and on omitted for brevity):</p> <pre class="lang-java prettyprint-override"><code>@FacesConverter("extendedDateTimeConverter") public class ExtendedDateTimeConverter extends DateTimeConverter { @Override public Object getAsObject(FacesContext context, UIComponent component, String value) { setPattern((String) component.getAttributes().get("pattern")); setTimeZone(TimeZone.getTimeZone((String) component.getAttributes().get("timeZone"))); return super.getAsObject(context, component, value); } @Override public String getAsString(FacesContext context, UIComponent component, Object value) { setPattern((String) component.getAttributes().get("pattern")); setTimeZone(TimeZone.getTimeZone((String) component.getAttributes().get("timeZone"))); return super.getAsString(context, component, value); } } </code></pre> <p>which can be used as</p> <pre class="lang-xml prettyprint-override"><code>&lt;h:outputText value="#{item.time}"&gt; &lt;f:converter converterId="extendedDateTimeConverter" /&gt; &lt;f:attribute name="pattern" value="yyyy-MM-dd HH:mm:ssZ" /&gt; &lt;f:attribute name="timeZone" value="#{item.timeZone}" /&gt; &lt;/h:outputText&gt; </code></pre> <p>This way the timezone is resolved everytime the converter is invoked instead of during its construction.</p> <hr> <p><strong>Update</strong>: the <a href="http://showcase.omnifaces.org/taghandlers/converter" rel="noreferrer">OmniFaces <code>&lt;o:converter&gt;</code></a> solves exactly this problem without the need for a custom converter.</p> <pre><code>&lt;h:outputText value="#{item.time}"&gt; &lt;o:converter converterId="javax.faces.DateTime" pattern="yyyy-MM-dd HH:mm:ssZ" timeZone="#{item.timeZone}" /&gt; &lt;/h:outputText&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload