1 Reply Latest reply on Apr 21, 2008 4:23 AM by Ilya Shaikovsky

    A4J, Selectonemenus  dependencies  and validation (r:message

    paata lominadze Master

      hello guys,
      i have two selectonemenu, first is parent and second is child, both of them must be required.
      i use jboss seam(2.0) framework with richfaces (3.4.1).
      my task is create ajax wizard (i found example about it), on first page i have two selectonemenus, which i described above.
      everything works fine except messaging for requirement.
      my code snippets :
      1.firstStep.xhtml

      ..........................
      <table>
      <tr>
      <td>
       <h:selectOneMenu id="dbType" styleClass="LoginLangCombo" value="#{dbparams.dbVendor}">
       <s:selectItems value="#{dbVendors.resultList}" var="vendor" label="#{vendor.dbvendorname}" />
       <s:convertEntity />
       <a4j:support event="onchange" reRender="dbType,dbDriverid" bypassUpdates="false"/>
       </h:selectOneMenu>
       </td>
      </tr>
      <tr>
      <td>
       <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>
       </td>
      </tr>
      </table>
      ..........................
      


      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;
       }
      }
      

      3.components.xml for database queries
      <framework:entity-home name="dbVendorHome" entity-class="com.magticom.billing.jbossmonitor.beans.entity.jits.DbVendor"/>
       <factory name="dbVendor" value="#{dbVendorHome.instance}"/>
       <framework:entity-query name="dbVendors" ejbql="select v from DbVendor v" order="v.id"/>
      
       <framework:entity-home name="dbDriverHome" entity-class="com.magticom.billing.jbossmonitor.beans.entity.jits.DbDriver"/>
       <factory name="dbDriver" value="#{dbDriverHome.instance}"/>
       <framework:entity-query name="dbDrivers" ejbql="select v from DbDriver v">
       <framework:restrictions>
       <value>v.dbVendor = #{dbparams.dbVendor}</value>
       </framework:restrictions>
       </framework:entity-query>
      


      1. validation is not working is second menu is empty.
      2.i tried to add required attribute for second menu, but after this filtering is not working.
      second menu filled every second time ignoring what i choose from first menu, every first time is empty.


      any idea will be appreciated.

      ______________________
      Regards.
      Paata Lominadze
      Magticom LTD.