2 Replies Latest reply on Sep 1, 2009 11:50 AM by lenyas66

    Use of custom validator - doesn't work on the click on Submi

    lenyas66

      I try to use custom validator on one of my comboBoxes and see that it works, when I try to select some value in comboBox, but doesn't if I have no value in it and just click on Submit button on the form. It doesn't go to the validator code in this case.

      The default validator does give me error message, if no value is selected. I don't like this message though and want to create my own message and that's the reason I use custom validator.

      Appreciate, if somebody could advise what prevents custom validator from working.

      Please see the code below:


      <rich:comboBox id="product" width="300" value="#{piQueryToolBean.product}"
       valueChangeListener="#{piQueryToolBean.changeBenchmark}"
       enableManualInput="true" converter="#{productConverter}" >
      
       <a4j:support event="onselect" reRender="benchmark,benchmarkList" ajaxSingle="true" />
       <f:selectItems id="productList" value="#{piQueryToolBean.productList}" />
       <f:validator validatorId="productValidator" />
       </rich:comboBox>
      ...
      <a4j:commandButton id="runButton" value="Run Report"
       action="#{piQueryToolBean.processInput}" immediate="false" reRender="reportheader,perfStatData"
       style="border-style:solid; border-color:#808080; color:#000000; background-color:#84BBFF;">
       </a4j:commandButton>
      ...
      public class ProductValidator implements Validator {
      
       public void validate(FacesContext context, UIComponent component, Object value)
       throws ValidatorException {
      
       boolean badProduct = false;
       if ( value == null)
       badProduct = true;
       else {
       final Account account = (Account)value;
       String key = account.getLongName();
       if ( key.equals("")) badProduct = true;
       }
       if ( badProduct )
       {
       FacesMessage message = new FacesMessage();
       message.setDetail("Product could not be empty");
       message.setSummary("Product could not be empty");
       message.setSeverity(FacesMessage.SEVERITY_ERROR);
       throw new ValidatorException(message);
       }
      
       }
      
      }
      ...