7 Replies Latest reply on Sep 5, 2013 3:25 AM by jlg29387

    How to update 2nd rich calendar when 1st rich calendar date changes

    jlg29387

      Hi,

       

      I'm looking for a way to update a 2nd (rich) calendar when the value of a 1st (rich) calendar changes. The idea is to keep a search date range within user-defined limits. So the user selects a start date, and the end date is selected automatically. If the user changes the end date, the start date does not change.

       

      I have seen examples using a4j, but so far nothing that I have tried is working (changes in the calendar do not trigger any kind of action). I am hoping to find a full example that works. Can anybody point me in the right direction?

       

      Thx!

        • 1. Re: How to update 2nd rich calendar when 1st rich calendar date changes
          bleathem

          Post the facelet code of what you have tried so far, and we'll see if we can determine what's going wrong.

          • 2. Re: How to update 2nd rich calendar when 1st rich calendar date changes
            jlg29387

            This the code:

             

            <h:outputText value="#{m.task_starDate}" />
            <rich:calendar id="starDate" value="#{taskBean.newTask.starDate}" >
                <a4j:support event="onchange" action="#{taskBean.changeEndDate}" reRender="endDate"/>
            </rich:calendar>
            <h:outputText value="#{m.task_endDate}" />
            <rich:calendar id="endDate" value="#{taskBean.newTask.endDate}">
            </rich:calendar>
            

             

            I've tried with OnChanged and onclick (Events) but can't get that when I select the start date, the end date calendar appear directly with the month and year of the start date selected.

             

            I've Tried wit currentDate too, but en mode popup I read that doesn't work.

             

            thanks.

            • 3. Re: How to update 2nd rich calendar when 1st rich calendar date changes
              jlg29387

              This seems to work. The problem now is that I can't change the date manually so when I hit the button I get the start date which is what I wanted but I also want to change it if I wish. I want that the dates can be different too.


              <h:outputText value="#{m.task_starDate}" />
              <rich:calendar id="starDate" value="#{taskBean.newTask.starDate}" >
              </rich:calendar>
              <h:outputText value="#{m.task_endDate}" />
              <rich:calendar id="endDate" value="#{taskBean.newTask.endDate}">
                  <a4j:support event="onclick" action="#{taskBean.changeEndDate}" reRender="endDate"/>
              </rich:calendar>
              
              • 4. Re: How to update 2nd rich calendar when 1st rich calendar date changes
                bleathem

                The first code snippet should be doing what you expected.  Can you post the code of your bean method: #{taskBean.changeEndDate}

                1 of 1 people found this helpful
                • 5. Re: How to update 2nd rich calendar when 1st rich calendar date changes
                  jlg29387

                  This is the code

                   

                  public void changeEndDate(){

                       newTask.setEndDate(newTask.getStartDay());

                  }

                   

                  The problem I have is that it will not let me select another date on the calendar "end date", directly when I click on the calendar write start date,  that is what I wanted but also I want that you can change it if you want.

                  • 6. Re: How to update 2nd rich calendar when 1st rich calendar date changes
                    bleathem

                    Javier López wrote:

                     

                    The problem I have is that it will not let me select another date on the calendar "end date", directly when I click on the calendar write start date,  that is what I wanted but also I want that you can change it if you want.

                     

                    What do you mean by "will not let me"?  What happens?  The data changes in the browser but not in the managed bean property?

                    • 7. Re: How to update 2nd rich calendar when 1st rich calendar date changes
                      jlg29387

                      I've found the error in the code. The onChanged event lacked the letter "d". This is the end code working properly. Thanks for the help.

                       

                        <rich:calendar id="startDate" value="#{taskBean.newTask.startDate}"  datePattern="dd/MM/yyyy">

                        <a4j:support event="onchanged" action="#{taskBean.changeEndDate}" reRender="endDate"/>

                        </rich:calendar>

                        <h:outputText value="#{m.task_endDate}" />

                        <rich:calendar id="endDate" value="#{taskBean.newTask.endDate}"  datePattern="dd/MM/yyyy">

                        </rich:calendar>

                       

                      Greetings.