2 Replies Latest reply on Aug 31, 2009 12:50 PM by gardellajuan

    Date Time Parameter Converter

      Hello,



      I am having problem to convert date time parameter.


      The date parameter from the component bean is :
      Sun Aug 30 00:00:00 ICT 2009


      I want convert to:
      Aug 30, 2009


      So, i declared converter in faces-config.xml:


      <converter>
        <converter-id>dateTimeConverter</converter-id>
        <converter-class>org.jboss.seam.ui.converter.DateTimeConverter</converter-class>
        <property>
         <property-name>pattern</property-name>
         <property-class>java.lang.String</property-class>
         <suggested-value>MMM dd, yyyy</suggested-value>
        </property>
       </converter>



      and then in AutomotiveReport.page.xml:


      <?xml version="1.0" encoding="UTF-8"?>
      <page xmlns="http://jboss.com/products/seam/pages"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.1.xsd">
       
       <navigation from-action="#{automotiveReport.automotiveReport}">
             <redirect include-page-params="true" view-id="/AutomotiveReports.xhtml"/>
       </navigation>
            <param converterId="dateTimeConverter" name="date" value="#{automotiveReport.date}"/>
      </page>



      But when i run, the converter dateTimeConverter never called. The parameter i got:



      http://localhost:8080/appl/run?__report=%2Freport%2Fautomotive.rptdesign&__format=pdf&__title=Automotive+Reports&date=Sun+Aug+30+00%3A00%3A00+ICT+2009&cid=13





      I hope the parameter like this:



      http://localhost:8080/appl/run?__report=%2Freport%2Fautomotive.rptdesign&__format=pdf&__title=Automotive+Reports&date=Aug 30, 2009&cid=13
      




      AutomotiveReport.xhtml


      <rich:calendar id="date" 
      value="#{automotiveReport.date}"
      required="true" 
      datePattern="MMM dd, yyyy"/>
      
      <div class="actionButtons">
           <h:commandButton id="automotiveReport" value="automotiveReport"
                          action="#{automotiveReport.automotiveReport}"/>
      </div>



      AutomotiveReport.java (component):



      @Stateful
      @Name("automotiveReport")
      @Scope(ScopeType.CONVERSATION)
      public class AutomotiveReportBean implements AutomotiveReport {
      
          @Logger private Log log;
      
          @In StatusMessages statusMessages;
      
          private Date date;
      
           public void automotiveReport()
          {
              // implement your business logic here
              log.info("automotiveReport.automotiveReport() action called with: #{automotiveReport.date}");
              statusMessages.add("automotiveReport #{automotiveReport.date}");
          }
          
      
           public Date getDate() {        
                return date;
           }
          
           public void setDate(Date date) {
                this.date = date;
           }
      
          @Remove
          @Destroy
          public void destroy() {}
      }



      AutomotiveReports.xhtml:



      <p:birt xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:s="http://jboss.com/products/seam/taglib"
                xmlns:p="http://jboss.com/products/seam/birt"
                xmlns:f="http://java.sun.com/jsf/core"
                    xmlns:h="http://java.sun.com/jsf/html"
                designType="run"
                format="pdf"
                designName="/report/automotive.rptdesign"
                title="Automotive Reports">
      
           <p:param name="date" value="#{automotiveReport.date}"/>
           
      </p:birt>




      Please help me....
      Thanks.

        • 1. Re: Date Time Parameter Converter
          lvdberg

          Hi,


          I think the converter is called while rendering and it doesn't pass the converter when you try to get a value from a bean. 
          You could use a helper method which does the trick for you, just create a method which return a String like this:



                         


          public String getMyDateString(date){
          SimpleDateFormat sdf = new SimpleDateFormat("MMM dd, yyyy");
          return sdf.format(date);
          
          }
          



          • 2. Re: Date Time Parameter Converter
            gardellajuan
            Hi

            Pass date in long format:

            <param name="myDate" value="#{bean.myDate.time}"/>