8 Replies Latest reply on Dec 7, 2008 5:33 PM by igor_d

    Calendar changes the empty input to previous value

    igor_d

      Hi,

      below is an example, when you have a rich:calendar and validation on change with reRender the calendar input.
      If you enter a value and hit "Search" link, then after that you'll not be able to clean the calendar input - it will change it back to the previous value. I don't think this is a correct JSF behaviour.

      <h:form>
       <h:outputText value="From" />
       <rich:calendar id="fromDate" datePattern="dd MMM yyyy"
      value="#{bean.entryDateStart}" enableManualInput="true" popup="true">
       <a4j:support
       ajaxSingle="true"
       event="oninputblur"
       reRender="fromDate"
       bypassUpdates="true"/>
       </rich:calendar>
       <a4j:commandLink value="search" action="#{bean.doSearch}"/>
      </h:form>
      

      Can that be related to https://jira.jboss.org/jira/browse/RF-3858?
      Thanks,
      Igor

        • 1. Re: Calendar changes the empty input to previous value
          ilya_shaikovsky

          yes. It's about this bug. should works in 3.2.2 GA

          • 2. Re: Calendar changes the empty input to previous value
            igor_d

            Hi Ilya,

            that's what we use - 3.2.2.GA and it does not work there :-(

            thanks,
            Igor

            • 3. Re: Calendar changes the empty input to previous value
              igor_d

              Is there any chance if someone from Richfaces great team could look at that issue for me?
              I mean, help with a workaround or create and fix the issue?

              • 4. Re: Calendar changes the empty input to previous value
                igor_d

                Hi,

                I need a respone on that issue.
                I would appreciate it if someone could have a look at this issue for me.

                Thanks,
                Igor

                • 5. Re: Calendar changes the empty input to previous value
                  ilya_shaikovsky

                  please reopen the bug with your page code in comment and presice steps to reproduce.

                  • 6. Re: Calendar changes the empty input to previous value
                    igor_d

                    Thanks, Ilya
                    I'm not sure if this is a bug, so I don't know if I should re-open the JIRA issue. But, here is my code.
                    mypage.xhtml:

                    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [ <!ENTITY nbsp " "> ]>
                    <html xmlns="http://www.w3.org/1999/xhtml"
                     xmlns:ui="http://java.sun.com/jsf/facelets"
                     xmlns:f="http://java.sun.com/jsf/core"
                     xmlns:h="http://java.sun.com/jsf/html"
                     xmlns:a4j="http://richfaces.org/a4j"
                     xmlns:c="http://java.sun.com/jstl/core"
                     xmlns:s="http://jboss.com/products/seam/taglib"
                     xmlns:ao="http://austrac.gov.au/ao"
                     xmlns:rich="http://richfaces.org/rich">
                    
                    <body>
                    <h:form>
                     <rich:calendar id="selectedDate" datePattern="dd MMM yyyy"
                     value="#{calendarBean.selectedDate}" enableManualInput="true"
                     popup="true">
                     <a4j:support ajaxSingle="true" event="oninputchange"
                     reRender="selectedDate" bypassUpdates="true" />
                     <a4j:support ajaxSingle="true" event="onchange"
                     reRender="selectedDate" bypassUpdates="true" />
                     </rich:calendar>
                     <h:commandButton />
                     <rich:messages />
                    </h:form>
                    </body>
                    </html>
                    


                    CalendarBean.java:
                    import java.util.Date;
                    
                    import org.jboss.seam.annotations.Name;
                    
                    @Name("calendarBean")
                    public class CalendarBean {
                     private Date selectedDate = new Date();
                    
                     public Date getSelectedDate() {
                     return selectedDate;
                     }
                    
                     public void setSelectedDate(Date selectedDate) {
                     this.selectedDate = selectedDate;
                     }
                    }
                    

                    Steps to reproduce:
                    You have a pre-populated date in the calendar input. Try to clear the input field, then exit (press tab), the previous value will come back.
                    I know, there is a button "clean" in the calendar popup, but not every user knows that.
                    Why we need to re-render on change - we wanted to instantly validate the user's input. If you remove <a4j:support> tags - the problem is gone.

                    My best regards,
                    Igor

                    • 7. Re: Calendar changes the empty input to previous value
                      igor_d

                      Sorry, correction:
                      the second "a4j:support" in mypage.xhtml should have event="onchanged", then it re-renders the calendar and puts the original value back. In this case even the button "clean" in popup does not clean the input field.

                      Thanks,
                      Igor

                      • 8. Re: Calendar changes the empty input to previous value
                        igor_d

                        we used a workarond: have a dateconverter which returns some fake date (not null) for empty string (we use new GregorianCalendar(0,0,0,0,0) and then use it in our validator and model update function to convert this date to null.

                        thanks,
                        Igor