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

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

    Leonid Sokolin Newbie

      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}"
       enableManualInput="true" converter="#{productConverter}" >
       <a4j:support event="onselect" reRender="benchmark,benchmarkList" ajaxSingle="true" />
       <f:selectItems id="productList" value="#{piQueryToolBean.productList}" />
       <f:validator validatorId="productValidator" />
      <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;">
      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");
       throw new ValidatorException(message);