1 Reply Latest reply on Jul 24, 2007 5:28 PM by Brian Smith

    Dependable dropdowns (Seam way)

    mgrouch Expert

      What is the best way to implement dependable dropdowns with Seam?
      (set of values in one depends on the other, full set of values in second one
      is too big to do it all client side)

      Thanks

        • 1. Re: Dependable dropdowns (Seam way)
          Brian Smith Apprentice

          I have used Ajax4JSF and seam to achieve this

          here is an example

          I have a list of LandmarkTypes and a List of Landmarks that is dependent on the LandmarkType chosen

           <a4j:region selfRendered="true">
           <h:selectOneMenu id="landmarkType_id"
           value="#{landmarkType}">
           <s:selectItems label="#{landType.landmarkTypeDescription}"
           value="#{allLandmarkTypes.resultList}"
           noSelectionLabel="(None)" var="landType"/>
           <s:convertEntity/>
           <a4j:support event="onchange"
           actionListener="#{addressLocator.fillLandmarkList}"
           ajaxSingle="true" reRender="landmark_input"/>
           </h:selectOneMenu>
           </a4j:region>
          
           <h:selectOneMenu id="landmark_input" value="#{landmark}">
           <s:selectItems label="#{land.landmarkName}"
           value="#{landmarkList}"
           noSelectionLabel="(None)" var="land"/>
           <s:convertEntity/>
           </h:selectOneMenu>


          The LandmarkTypes are filled using a CRUD entity-query ("allLandmarkTypes") but could just as easily be done using an @Factory method.

          Here is the sfsb. I am using lazy loading to fill the list but a query would work just as well.

           @In(required=false)
           private LandmarkType landmarkType;
          
           @Out(required=false)
           List<Landmark> landmarkList;
          
           public void fillLandmarkList() {
           if (!(entityManager.contains(landmarkType))) {
           landmarkType = entityManager.getReference(LandmarkType.class, landmarkType.getLandmarkTypeId());
           }
           landmarkList = (List) landmarkType.getLandmarkCollection();
          
           }