2 Replies Latest reply on May 3, 2011 6:08 AM by its_me

    rich:calendar issue

    its_me

      Hello All,

       

      I have a rich:calendar on my search screen. I use the date selected on the calendar, and populate the data from the db based upon the dates selected. The following is my code:

       

                                         <rich:calendar id="custFromCal" value="#{myBean.strCustomFromDate}"
                                                         popup="#{myBean.popup}" locale="#{myBean.locale}"
                                                         datePattern="#{myBean.pattern}"
                                                         showApplyButton="true" style="width:200px" />
                                          <a4j:commandLink onclick="$('searchForm:custFromCal').component.doExpand(event)" />


                                          <rich:calendar id="custToCal" value="#{myBean.strCustomToDate}"
                                                         popup="#{myBean.popup}"
                                                         datePattern="#{myBean.pattern}" locale="#{myBean.locale}"
                                                         showApplyButton="true" style="width:200px"/>
                                          <a4j:commandLink onclick="$('searchForm:custToCal').component.doExpand(event)" />

       

      The corresponding bean code is,

       

      private String strCustomFromDate;
          private String strCustomToDate;
          private static final String[] WEEK_DAY_LABELS = new String[] { "Sun *",  
                  "Mon +", "Tue +", "Wed +", "Thu +", "Fri +", "Sat *" };  
          private Locale locale;  
       
          private boolean popup = true ;  
          private boolean readonly = true;  
          private boolean showInput = true;  
          private boolean enableManualInput = false;      
          private String pattern;  
          private Date currentDate;  
          private Date selectedDate;  
          private String jointPoint;  
          private String direction;  
          private String boundary;

          public String getBoundary() {
              if (null == boundary){
                   boundary = "inactive"; 
              }
              return boundary;
          }

          public void setBoundary(String boundary) {
              this.boundary = boundary;
          }

          public Date getCurrentDate() {
              return currentDate;
          }

          public void setCurrentDate(Date currentDate) {
              this.currentDate = currentDate;
          }

          public String getDirection() {
              if (null == direction){
                  direction = "bottomright";
              }
              return direction;
          }

          public void setDirection(String direction) {
              this.direction = direction;
          }

          public boolean isEnableManualInput() {
              return enableManualInput;
          }

          public void setEnableManualInput(boolean enableManualInput) {
              this.enableManualInput = enableManualInput;
          }

          public String getJointPoint() {
              if (null == jointPoint){
                   jointPoint = "bottomleft"; 
              }
            
              return jointPoint;
          }

          public void setJointPoint(String jointPoint) {
              this.jointPoint = jointPoint;
          }

          public Locale getLocale() {
              if (null == locale){
                  locale = Locale.US;
              }
              return locale;
          }

          public void setLocale(Locale locale) {
              this.locale = locale;
          }

          public String getPattern() {
               if (null == pattern){
                   pattern = "MM/dd/yyyy HH:mm";
              }
             
              return pattern;
          }

          public void setPattern(String pattern) {
              this.pattern = pattern;
          }

          public boolean isPopup() {
             
              return popup;
          }

          public void setPopup(boolean popup) {
              this.popup = popup;
          }

          public boolean isReadonly() {
              return readonly;
          }

          public void setReadonly(boolean readonly) {
              this.readonly = readonly;
          }

          public Date getSelectedDate() {
              return selectedDate;
          }

          public void setSelectedDate(Date selectedDate) {
              this.selectedDate = selectedDate;
          }

          public boolean isShowInput() {
              return showInput;
          }

          public void setShowInput(boolean showInput) {
              this.showInput = showInput;
          }
         
         

          public String getStrCustomFromDate() {
              return strCustomFromDate;
          }

          public void setStrCustomFromDate(String strCustomFromDate) {
              this.strCustomFromDate = strCustomFromDate;
          }

          public String getStrCustomToDate() {
              return strCustomToDate;
          }

          public void setStrCustomToDate(String strCustomToDate) {
              this.strCustomToDate = strCustomToDate;
          }

       

      When I select the date and time on screen, the date comes in proper format eg: 04/24/2011 12:00 as in the bean. But while running it from server side, I get Sun Apr 24 12:00:00 GMT+05:30 2011 as date.

       

      I need to remove this discrepancy. Is there any setting that I am missing?

       

      Any help is appreciated.

       

      Thanks and Regards,

      Nid.

        • 1. Re: rich:calendar issue
          ppitonak

          Hi,

           

          Sun Apr 24 12:00:00 GMT+05:30 2011 is a standard output of class java.util.Date. If you want to convert it to the MM/dd/yyyy HH:mm format, you can use SimpleDateFormat:

           

          SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm");

          sdf.format(currentDate);

           

          Regards,

          Palo

          1 of 1 people found this helpful
          • 2. Re: rich:calendar issue
            its_me

            Thanks Palo,

             

            Your approach helped open a new perpective in the code. Improving on your idea, Adding the following code did help on server side:

             

            SimpleDateFormat format =  new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
                        Date parsed = format.parse("Mon May 02 14:25:16 GMT+05:30 2011");
                          SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm");                

                        String parsed1 =  sdf.format(parsed);                    
                      
            We can apply the same logic on client's side too.

            We can have a javascript event to capture the value in date format and set it as a hidden value on the xhtml page. This helps too.

            var fromv=$('searchForm:custFromCal').component.getSelectedDateString("MM/dd/yyyy HH:mm");

             

            Thanks and Regards,

            Nid..........

            1 of 1 people found this helpful