6 Replies Latest reply on Jun 28, 2008 8:28 AM by Ilya Shaikovsky

    Calendar - Send Date to Server

    E Aish Novice

      Hi,

      Can anyone please guide me with this calendar functionality?

      The requirement is to get two dates (From Date and To date) from the user. Based on the selected date the data from the backend data base tables have to retrieved and displayed below the date.

      So, I need to have two fields and a commandButton on the screen and a ajax region. When the user selects the two dates and press the commandbutton and the database details for the selected date should be rerenderd in the ajax region.

      Given below is the code Istarted with, but have but I am struck.. I am not sure where the value of the selected date is stored and how it can be accessed in the backend bean?


      Your help is truly appreciated

      Thanks
      Aish


      <rich:calendar id="myCalendar1" popup="true"
      value="#{TableDetail.datedefault1}"
      showApplyButton="true" showInput="true"/>

      <rich:calendar id="myCalendar2" popup="true"
      value="#{TableDetail.datedefault2}"
      showApplyButton="true" showInput="true"/>

      <a4j:commandButton id="Button" value="Select" reRender="table" immediate="true" >
      In the bacend bean
      =============
      public Date getDatedefault1()
      {

      String ds1 = "January 1, 2008";
      DateFormat df = DateFormat.getDateInstance();
      try
      {
      datedefault = df.parse(ds1);
      }
      catch (ParseException e)
      {
      System.out.println("parse Exception occured in datedefault");
      }
      return datedefault;
      }

        • 1. Re: Calendar - Send Date to Server
          Lance Buchan Newbie

          Hi Aish

          Well, firstly ensure you have the exact property 'datedefault1' and also ensure 'TableDetail' is the exact name of your bean as declared in faces-config.xml.

          Additionally, I don't see a 'setDatedefault1(Date defaultdate1)' method in your bean code?

          Cheers
          Lance

          • 3. Re: Calendar - Send Date to Server
            E Aish Novice

            Hi Lance,

            Thank you so much for your reply with the code. I helped me to get it to work. I really appreciate your help.


            Regards
            Aish

            • 4. Re: Calendar - Send Date to Server
              E Aish Novice

              Hi Lance,

              I have a quick question about the date. Can you please help me with it?

              As I have stated in my first post, I have two date fields on my form - FromDate and ToDate. I am using the rich:calendar as suggested your code. I would like to point the ToDate as the current Date and the From Date as 30 days priot to ToDate. For eg: FromDate would May 25 and To Date would be June 25.

              I checked the java date and looks like java calendar supports subtraction operation and the java date does not support arithmetic operation. If I use Calendar as given in the code below, the result is a "Calendar" and not a Date type to be used by <rich:calendar>

              Can you please let me know how I can get the currentDate "minus" 30 days and set it to FromDate as rich:calendar?

              Thanks
              Aish

              Calendar calendar = Calendar.getInstance();

              calendar.add(Calendar.DAY_OF_MONTH, -10);

              • 5. Re: Calendar - Send Date to Server
                E Aish Novice

                Hi Lancey,

                I wanted to check with you about the calendar on one thing. I used
                " enableManualInput="true" but the date is not stored in the back end bean as it does in the date selected by the popup date? Should I need to add any other option?

                Thanks a lot for your help on this
                Aish

                <rich:calendar id="ToDateCal" value="#{TableDetail.toDate}"
                popup="true"
                datePattern="#{TableDetail.pattern}"
                enableManualInput="true"
                showApplyButton="false"
                style="width:100px"
                disabled='#{TableDetail.selected == true}'>
                <a4j:support ajaxSingle="true" event="ondateselected" reRender="metricsTable" />

                • 6. Re: Calendar - Send Date to Server
                  Ilya Shaikovsky Master

                  check please oninput* events provided and add one more support ;)