3 Replies Latest reply on Jul 24, 2008 8:40 AM by lcurros

    PASS VALUE TO JSF VALIDATOR


      Hi,


      I am trying to do a JSF validator to test if one date is after other reference date.
      Both dates are in the same form and I need to pass both to the validator.


      My firs approach is this:


      This is the class to make validation


      @Name("validators")
      public class Validators implements Serializable {
           public void validateAfter(FacesContext context, 
                     UIComponent toValidate,
                     Object value) {
                     
                      Date referenceDate = (Date) toValidate.getAttributes().
                       get("validatorParam1");
                     Date dateValue= (Date) value;
      
                     
                     if (!dateValue.after(referenceDate)) {
                          ((UIInput)toValidate).setValid(false);
      
                          FacesMessage message = new FacesMessage("My message");
                          context.addMessage(toValidate.getClientId(context), message);
                     }
      
           }
      
      }
      



      And this is the view:



      <h:form id="mainForm">
           <s:decorate id="startDateDec" template="/layout/editCustom.xhtml">
                <rich:calendar value="#{entityHome.instance.startDate}"/>
           </s:decorate>
           <s:decorate id="endDateDec"     template="/layout/editCustom.xhtml">
                <rich:calendar value="#{entityHome.instance.endDate}"
                     validator="#{validators.validateAfter}">
                     <f:attribute name="validatorParam1"
                          value="#{entityHome.instance.startDate}" />
                     <s:validate />
                </rich:calendar>
           </s:decorate>
      </h:form>



      But the referenceDate is always null.


      How to solve this?



      Thanks in advance.