3 Replies Latest reply on Oct 5, 2012 2:01 AM by akb

    RF4 rich:calendar not binding new value on AJAX change event

    sbalmos1

      Hi all,

       

      I'm wondering what I'm doing wrong. Under RF4 final, I've got a rich:calendar with an AJAX tag to re-render another control after I've selected a date. The event fires and the other control goes to re-render. But the newly-selected value from the calendar is not being bound into the backing bean's field. I've tried with both f:ajax and a4j:ajax, with and without execute="@this".

       

      In my JSF page:

      <rich:calendar id="birthDate" value="#{employeeMgmtBean.generalBean.employee.birthDate}" datePattern="M/d/yyyy" required="true">
        <a4j:ajax event="change" render="age"/>
      </rich:calendar>
      <h:outputText id="age" value="#{employeeMgmtBean.generalBean.age}"/>
      

       

      In the Employee bean:

      public Date getBirthDate() {
        return birthDate;
      }
      
      
      public void setBirthDate(Date birthDate) {
        this.birthDate = birthDate;
      }
      
      

       

      And in the General bean:

      public Double getAge() {
        DateTime birthDate = new DateTime(employee.getBirthDate());
        DateTime now = new DateTime();
        int daysBetween = Days.daysBetween(birthDate, now).getDays();
        return new BigDecimal(daysBetween).divide(new BigDecimal(365), 1, BigDecimal.ROUND_UP).doubleValue();
      }
      

       

      Like I said, I can confirm getAge() is being called again after I select a new date from the calendar. But the new birthDate value is not bound into the field, which makes recalling getAge() useless. What gives? Thanks!

        • 1. Re: RF4 rich:calendar not binding new value on AJAX change event
          djnose

          i think i did something similar. You may want to create a listener and check the value there.

          I think <a4j:event> does not submit your form and so the new value is not available.

          You may try something like:

           

          <a4j:ajax event="change" render="age" execute="@this" listener="#{employeeMgmtBean.changeListener}"/>

          in your bean you create a listener like that:

           

                  public void changeListener(AjaxBehaviorEvent ab) {
                     
          if (ab != null && ab.getSource() != null && ab.getSource() instanceof UICalendar) {
                                 UICalendar calendar = (UICalendar) ab.getSource();
                  Date value = (Date) calendar.getValue();
                      // dont know if it is date or not just try
                                if (value != null) {
                    
          // and so on...
                                  }
                 }
                  }

           

          i hope it helps!

          • 2. Re: RF4 rich:calendar not binding new value on AJAX change event
            sbalmos1

            I really wish I knew why <a4j:event> does not submit the form. Actually, I'm just hoping this is another RF4 stupidity that hopefully will be fixed in 4.1 or sometime soon. Apparently creating a listener did it. The listener didn't even have to do anything. So now, I have code as follows that works:

             

            <f:ajax event="change" listener="#{rf4KludgesBean.bindCalendarValue}" render="age"/>
            

             

            in RF4KludgesBean (yes, I have a separate bean solely for RF4 workarounds):

             

            public void bindCalendarValue() {}
            

             

            And everything works. *grumble*. Thanks for the idea though.

            • 3. Re: RF4 rich:calendar not binding new value on AJAX change event
              akb

              Try out

              <a4j:support event="onchanged" reRender="age" />