2 Replies Latest reply on Apr 8, 2009 7:20 PM by francof

    Date range checks on rich:calendar

      I have 2 dates (start and end) bound to rich:calendar
      What I am trying to achieve is -
      - if one of the dates is entered and the other is blank, then it is required.
      - if both are entered, they should be validated for correctness - start should not be later than end.

      I don't have a problem with the second. I just can't seem to get the required attribute generated correctly for these dates.

      Here is my markup

      <s:decorate id="featureStartDateDecoration" >
      <rich:calendar id="featureStartDate"
       value="#{catalogItemHome.instance.featureStartDate}"
       datePattern="MM/dd/yyyy"
       inputSize="10"
       process="featureEndDate"
       ajaxSingle="true"
       required="#{catalogItemHome.instance.featureEndDate != null ? true : false}"
       requiredMessage="Feature start date is required if you enter end date"
       >
       <a4j:support event="onchanged" action="#{catalogItemHome.validateFeatureDateRange}"
       reRender="featureStartDateDecoration,featureEndDateDecoration"/>
      
      </rich:calendar>
      </s:decorate>
      
      <s:decorate id="featureEndDateDecoration" >
      <rich:calendar id="featureEndDate"
       value="#{catalogItemHome.instance.featureEndDate}"
       datePattern="MM/dd/yyyy"
       inputSize="10"
       process="featureStartDate"
       ajaxSingle="true"
       required="#{catalogItemHome.instance.featureStartDate != null ? true : false}"
       requiredMessage="Feature end date is required if you enter start date"
       >
       <a4j:support event="onchanged" action="#{catalogItemHome.validateFeatureDateRange}"
       reRender="featureStartDateDecoration,featureEndDateDecoration"/>
      </rich:calendar>
      </s:decorate>



      Let's say I have values for these dates when I start

      I go to start date, and hit Clean button on the calendar to clear the value.
      So it's required message is shown because end date still has a value. Ok.

      Now I clean the end date too and this time both fields required messages are displayed.

      Is it possible to do what I am doing or should I validate this at form level?

      using RF 3.3

      Thanks
      Franco




        • 1. Re: Date range checks on rich:calendar

          After some playing, I found

          hitting the Clean button does not trigger my onchanged event, so basically I still have the old value.
          That explains why my expression
          required="#{catalogItemHome.instance.featureEndDate != null ? true : false}"

          sees no change.

          Is there an event that gets fired when the calendar value is cleared ?
          Also, is the value null as I am thinking ?


          • 2. Re: Date range checks on rich:calendar

            I am rethinking this after finding some more threads in this forum.

            I will write a validator and attach it to the end date.

            Thanks
            Franco