3 Replies Latest reply on Jul 9, 2009 2:54 AM by Roger Mori

    Page parameter containing the time

    Dan Keyes Newbie

      I would like to pass an instance of Date as a page parameter, so I added the following line to an xxx.page.xml file.


      
      <param name="startDate" value="#{xxxList.startDate}" converterId="org.jboss.seam.ui.DateTimeConverter" />
      
      



      The parameter that was passed only contained the date.  There was not time information.  The param in the URL was as follows.


      startDate=Jul+2%2C+2009
      



      Is it possible to pass the time as a page parameter?  How is it done?

        • 1. Re: Page parameter containing the time
          Arbi Sookazian Master

          remember JBoss EL (pass params in EL):


          <h:commandButton value="foo" action="#{myBean.myMethod(new Date())}"/>



          MyBean:


          @Name("myBean")
          public class MyBean{
             public void myMethod(java.util.Date date){
              //do stuff
             }
          
          }



          Have you tried something like this?

          • 2. Re: Page parameter containing the time
            Dan Keyes Newbie

            John,


            The Date and Time are transfered correctly from the JSF page to my backing bean.  I used the following code in the .xhtml page.



            
            <s:decorate id="startTimeDecorate" template="layout/edit.xhtml" rendered="#{xxxList.scopeOption == 3}">
                <ui:define name="label">Start Time</ui:define>
                <h:inputText id="startTime" value="#{xxxList.startDate}">
                    <s:convertDateTime timeZone="#{timeZone}" locale="#{locale}" type="both" style="short" />
                    <a4j:support event="onblur"  reRender="startTimeDecorate"></a4j:support>
                </h:inputText>                  
            </s:decorate>
            
            



            The Start Time is sent to the server using AJAX, and I can see that it gets there correctly with both the date and the time.  I believe that the JSF page works correctly, because I can set the type attribute to both.  The problem occurs when I hit the search button and the parameters are passed to the result page using page parameters.  As shown earlier, the start time param is passed with the following line in xxx.page.xml file.


            <param name="startDate" value="#{xxxList.startDate}" converterId="org.jboss.seam.ui.DateTimeConverter" />
            



            I believe the problem is that the type is probably defaulting to date rather than both.  I attempting to solve the problem by creating a custom converter that extends the org.jboss.seam.ui.DateTimeConverter.  In the constructor, I set the type to both using the setType method.  Unfortunately, I'm getting a FacesException that indicates that it can't find my custom converter.  I put it into a jar the xxx.ear\xxx.war\WEB-INF\lib directory, but it isn't found. 


            Does anyone have any ideas for a solution?

            • 3. Re: Page parameter containing the time
              Roger Mori Newbie

              Hi Dan.


              I have created an application scope component to deal with the same issue of passing datetime parameters. Hope this solution will  help you.


              Roger.



              Java class



              package com.hersys.utils.date;
              
              import java.text.DateFormat;
              import java.util.Date;
              import java.util.TimeZone;
              
              import org.jboss.seam.ScopeType;
              import org.jboss.seam.annotations.Name;
              import org.jboss.seam.annotations.Scope;
              import org.jboss.seam.annotations.Startup;
              
              
              /*
               *  DateFormatter formats a date into a string according to the server Timezone
               *  Usage:  to surpass the limitation of f:param unable to be used with datetime converter
               *      
               */
              
              public class DateFormatter  {
                  private TimeZone timeZone;
                   private DateFormat dateFormat = DateFormat.getDateTimeInstance();
                   
                  public String format(Date date) {
                    if (date == null) {
                         return null;
                    }
                    return dateFormat.format(date);
                  }
                   public TimeZone getTimeZone() {
                        return timeZone;
                   }
                   public void setTimeZone(TimeZone timeZone) {
                        this.timeZone = timeZone;
                        dateFormat.setTimeZone(timeZone);
                   }
                  
              }
              



              Component Configuration



              components.xml
              
              <component name="DATE_FORMATTER" class="com.hersys.utils.date.DateFormatter"  auto-create="true" scope="application" >
                     <property name="timeZone">#{timeZone}</property>
                   </component>
              
              



              Link on view



              <s:link view="/sf/TaskList.xhtml"
                value="#{workingDay.highPriorityTasks}"
                includePageParams="true"
                rendered="#{workingDay.highPriorityTasks ne 0}"
                propagation="none"
              
              <f:param name="fromDueDate"      
              value="#{DATE_FORMATTER.format(workingDay.actionDate)}"  />
              
              <f:param name="toDueDate"        value="#{DATE_FORMATTER.format(workingDay.actionDate)}" />
              
              </s:link>
              
              



              Parameter Configuration



              
              <param name="fromDueDate" value="#{DATE_RANGE.startDate}" converterId="org.jboss.seam.ui.DateTimeConverter"/>
              
                 <param name="toDueDate" value="#{DATE_RANGE.endDate}" converterId="org.jboss.seam.ui.DateTimeConverter" />