3 Replies Latest reply on Feb 5, 2009 3:10 PM by Stefano Travelli

    TimeZone Conversion

    Cody Lerum Apprentice

      I've searched in the forum and in the docs and not found a good answer to this so hopefully someone has dealt with this before me.


      I want to have all my database times stored in GMT time and then convert datetime per user.


      In order to get my datetime correct in the database when persisting I used -Duser.timezone=GMT in my Server Launch arguments and that works.


      I'm trying then to test my convertdatetime and it's blowing up on me. The docs say that timeZone in s:convertDateTime takes a string so I've tried a couple options MST7MDT and America/Denver and both blow up. See trace below.


      What am I missing here?


                      <rich:column> 
                          <f:facet name="header">Created</f:facet> 
                          <h:outputText value="#{lead.createdDate.getTime()}">
                               <s:convertDateTime type="both" timeZone="America/Denver" pattern="MM/dd/yyyy"/>
                          </h:outputText>
                      </rich:column> 
      






      java.lang.IllegalArgumentException: Cannot convert America/Denver of type class java.lang.String to class java.util.TimeZone
           at org.jboss.el.lang.ELSupport.coerceToType(ELSupport.java:358)
           at org.jboss.el.ExpressionFactoryImpl.coerceToType(ExpressionFactoryImpl.java:46)
           at org.jboss.seam.el.SeamExpressionFactory.coerceToType(SeamExpressionFactory.java:70)
           at com.sun.facelets.tag.BeanPropertyTagRule$LiteralPropertyMetadata.applyMetadata(BeanPropertyTagRule.java:45)
           at com.sun.facelets.tag.MetadataImpl.applyMetadata(MetadataImpl.java:36)
           at com.sun.facelets.tag.MetaTagHandler.setAttributes(MetaTagHandler.java:62)
           at com.sun.facelets.tag.jsf.ConvertHandler.apply(ConvertHandler.java:116)
           at com.sun.facelets.tag.jsf.ComponentHandler.applyNextHandler(ComponentHandler.java:314)
           at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:169)
           at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
           at com.sun.facelets.tag.jsf.ComponentHandler.applyNextHandler(ComponentHandler.java:314)
           at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:169)
           at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
           at com.sun.facelets.tag.jsf.ComponentHandler.applyNextHandler(ComponentHandler.java:314)
           at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:169)
           at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
           at com.sun.facelets.tag.jsf.ComponentHandler.applyNextHandler(ComponentHandler.java:314)
           at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:169)
           at com.sun.facelets.tag.ui.DefineHandler.applyDefinition(DefineHandler.java:64)
           at com.sun.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:131)
           at com.sun.facelets.impl.DefaultFaceletContext$TemplateManager.apply(DefaultFaceletContext.java:337)
           at com.sun.facelets.impl.DefaultFaceletContext.includeDefinition(DefaultFaceletContext.java:307)
           at com.sun.facelets.tag.ui.InsertHandler.apply(InsertHandler.java:68)
           at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
           at com.sun.facelets.tag.jsf.core.ViewHandler.apply(ViewHandler.java:109)
           at com.sun.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:49)
           at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
           at com.sun.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:25)
           at com.sun.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:248)
           at com.sun.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:294)
           at com.sun.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:273)
           at com.sun.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:140)
           at com.sun.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:113)
           at com.sun.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:49)
           at com.sun.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:25)
           at com.sun.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:95)
           at com.sun.facelets.FaceletViewHandler.buildView(FaceletViewHandler.java:524)
           at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:567)
           at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
           at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:196)
           at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
           at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
           at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
           at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:177)
           at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:267)
           at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:380)
           at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:507)
           at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
           at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
           at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
           at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
           at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
           at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
           at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
           at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
           at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
           at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
           at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
           at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
           at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
           at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:601)
           at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
           at java.lang.Thread.run(Unknown Source)
      

        • 1. Re: TimeZone Conversion
          Stefano Travelli Newbie

          timeZone attribute expects a TimeZone instance, not a time zone ID.


          Provide a getter for the timezone in a session scoped component representing the user currently logged in, so that you can write:



            <rich:column> 
              <f:facet name="header">Created</f:facet> 
              <h:outputText value="#{lead.createdDate.getTime()}">
                <s:convertDateTime
                     type="both" 
                     timeZone="#{currentUser.timeZone}"
                     pattern="MM/dd/yyyy"/>
               </h:outputText>
            </rich:column> 
          




          • 2. Re: TimeZone Conversion
            Cody Lerum Apprentice

            Where do you see that it is looking for a TimeZone and not a string?


            I shouldn't trust http://www.jsftoolbox.com/documentation/seam/09-TagReference/seam-convertDateTime.html


            but The 2.1.1GA Docs says it doesn't even take attributes.

            • 3. Re: TimeZone Conversion
              Stefano Travelli Newbie

              First I see the error you posted:




              java.lang.IllegalArgumentException: Cannot convert America/Denver of type class java.lang.String to class java.util.TimeZone
                   at org.jboss.el.lang.ELSupport.coerceToType(ELSupport.java:358)


              Then, in IDEA, I press ctrl-q on the attribute in order to get the description:




              Time zone in which to interpret any time information in the date String. Value must be either a VB expression that evaluates to a java.util.TimeZone instance, or a String that is a timezone ID as described in the javadocs for java.util.TimeZone.getTimeZone().

              However this description is inaccurate as it states that the attribute could also be a String to be evaluated by TimeZone.getTimeZone(), which is not true.
              Actually the attribute is EL only.


              Finally, I look at how the tag is used in the sample applications (blog and wiki).