jsfjsf-1.2jboss-seam

ConvertDateTime does not get timezone defined in web.xml


I'm using f:convertDateTime to format a dateTime in a datatable. I set the following context parameter in web.xml to explicitly set the timezone to system timezone:

<context-param>
    <param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name>
    <param-value>true</param-value>
</context-param>

For some reason my convertDateTime gets "GMT" always, but the correct timezone is "GMT-03:00". I tried this in a test class to see my timezone:

System.out.println(TimeZone.getDefault().getDisplayName());

which gives me "GMT-03:00".

I'm using JSF 1.2 and JBoss Seam 2.2, the jboss-seam DateTimeConverter is called to make this conversion, I don't know if this is the problem.


Solution

  • I'm using JSF 1.2

    The mentioned context param is introduced in JSF 2.0. It's not available in JSF 1.x. See also a.o. Set a default time zone for f:convertDateTime. In other words, it's simply never used. Remove it to avoid confusion.

    You've 2 options:

    1. Explicitly specify timeZone in every <f:convertDateTime>.

      <h:xxx ...>
          <f:convertDateTime ... timeZone="GMT-3" />
      </h:xxx>
      

      If necessary as application scoped bean property.

      <h:xxx ...>
          <f:convertDateTime ... timeZone="#{config.timeZone}" />
      </h:xxx>
      

    2. Extend the date time converter with a new default time zone (and other properties).

      public class DefaultDateTimeConverter extends DateTimeConverter {
      
          public DefaultDateTimeConverter() {
              setType("both");
              setTimeZone(TimeZone.getTimeZone("GMT-3"));
          }
      
      }
      

      <converter>
          <converter-id>defaultDateTimeConverter</converter-id>
          <converter-class>com.example.DefaultDateTimeConverter</converter-class>
      </converter>
      

      And then replace <f:convertDateTime> with it.

      <h:xxx ... converter="defaultDateTimeConverter" />