1 Reply Latest reply on Apr 12, 2010 10:00 PM by flavioborsatto

    Null Pointer Exception EqualityValidator

    flavioborsatto

      When the object that is passed in tag (s:equalityValidator) parameter for is null, and the operator grater or less is choosed it throws a nullPointerException... somebody already saw this?




      <rich:calendar label="Initial Date" id="dtIni" inputClass="dtVldIni" inputSize="16" value="#{backBean.dtIni}" datePattern="dd/MM/yyyy" showApplyButton="false">
      </rich:calendar>
              
      <h:outputText value="-" style="margin:0 5px" />
           
      <rich:calendar label="Final Date" id="dtFin" inputClass="dtVldFin" inputSize="16" value="#{backBean.finDate}" datePattern="dd/MM/yyyy" showApplyButton="false" 
      <s:validateEquality for="dtIni" operator="greater" required="false"/>
      </rich:calendar>





      thanks

        • 1. Re: Null Pointer Exception EqualityValidator
          flavioborsatto


            public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException
             {
                if (getFor() == null)
                {
                   throw new FacesException("Must specify a component to validate equality against");
                }
                UIComponent otherComponent = findOtherComponent(component);
          
                Object other = new OtherComponent(context, otherComponent).getValue();
                if (value == null && other == null) *// THIS SHOULD BE AN || ?????*
                {
                   // Thats fine 
                }
                else if (value != null)
                {
                   switch (operator)
                   {
                   case EQUAL:
                      if (!value.equals(other))
                      {
                         throwValidationException(value, otherComponent, other);
                      }
                      break;
                   case NOT_EQUAL:
                      if (value.equals(other))
                      {
                         throwValidationException(value, otherComponent, other);
                      }
                      break;
                   case GREATER:
                      if (!(compare(value, other) > 0))
                      {
                         throwValidationException(value, otherComponent, other);
                      }
                      break;
                   case GREATER_OR_EQUAL:
                      if (!(compare(value, other) >= 0))
                      {
                         throwValidationException(value, otherComponent, other);
                      }
                      break;
                   case LESS:
                      if (!(compare(value, other) < 0))
                      {
                         throwValidationException(value, otherComponent, other);
                      }
                      break;
                   case LESS_OR_EQUAL:
                      if (!(compare(value, other) <= 0))
                      {
                         throwValidationException(value, otherComponent, other);
                      }
                      break;
                   }
                }
             }