0 Replies Latest reply on Apr 17, 2008 3:35 AM by paata lominadze

    how to validate empty selectonemenu ?

    paata lominadze Master

      hi all,
      i have simple question.
      i have one selectonemenu and rich message for it, also i have selectonemenu validation.
      validation works if i have elements into selectonemenu, but it is emptyu validation does not work.
      code snippets:
      1.view :

       <h:selectOneMenu id="dbDriverid" styleClass="LoginLangCombo" value="#{dbparams.dbDriver}">
       <s:selectItems value="#{dbDrivers.resultList}" var="driver" label="#{driver.dbDriverName}"/>
       <s:convertEntity />
       <f:validator validatorId="SelectValidator"/>
       </h:selectOneMenu>
       <rich:message for="dbDriverid"
       ajaxRendered="true"
       tooltip="true"
       showDetail="false"
       showSummary="true"
       passedLabel="No Error"
       errorLabelClass="errorLabel"
       fatalLabelClass="warnLabel"
       infoLabelClass="infoLabel"
       warnLabelClass="fatalLabel"
       title="this is tooltip">
       <f:facet name="errorMarker">
       <h:graphicImage url="/img/error.gif"/>
       </f:facet>
       <f:facet name="fatalMarker">
       <h:graphicImage url="/img/fatal.gif"/>
       </f:facet>
       <f:facet name="infoMarker">
       <h:graphicImage url="/img/info.gif"/>
       </f:facet>
       <f:facet name="warnMarker">
       <h:graphicImage url="/img/warn.gif"/>
       </f:facet>
       <f:facet name="passedMarker">
       <h:graphicImage url="/img/passed.gif"/>
       </f:facet>
       </rich:message>
      

      2. validator :
      public class SelectValidator implements Validator {
      
       public SelectValidator() {
       }
      
       public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
       System.out.println("SelectValidator.validate()");
      
       DbDriver dbDriver = (DbDriver) value;
       String clientId = component.getClientId(context);
       int componentNum = componentNum(component.getId());
       System.out.println("selectedValue = " + dbDriver);
       System.out.println("clientId = " + clientId);
       System.out.println("componentNum = " + componentNum);
      
       if (dbDriver == null) {
       FacesMessage message = new FacesMessage();
       message.setSummary("warning SUMMARY for: " + componentNum + " input");
       message.setDetail("warning DETAIL for: " + componentNum + " input");
       message.setSeverity(FacesMessage.SEVERITY_WARN);
       context.addMessage(clientId, message);
       }
       }
      
       public int componentNum(String baseId) {
      
       if (baseId.endsWith("1")) {
       return 1;
       } else if (baseId.endsWith("2")) {
       return 2;
       } else if (baseId.endsWith("3")) {
       return 3;
       } else if (baseId.endsWith("4")) {
       return 4;
       }
      
       return -1;
       }
      



      any ideas ?
      any idea will be appreciated.


      _____________________
      Regards.
      Paata Lominadze
      Magticom LTD.