11 Replies Latest reply on Dec 13, 2008 4:26 PM by visumagic

    Fill SelectOnemenu filtered by another one (using a4j)

    paata.paatal.magtigsm.ge

      hi all,
      i use seam, richfaces and ajax4jsf frameworks for my application,
      i have simple question.


      i need populate one selectonemenu - A filtered by another selectonemenu - B . how i can do it ?


      here is my code snippets :


      1.view


      <h:selectOneMenu id="dbType" styleClass="LoginLangCombo" value="#{dbparams.dbVendor}">                        
                              <s:selectItems value="#{dbVendors.resultList}" var="vendor" label="#{vendor.dbvendorname}" noSelectionLabel="Please Select DataBase ... "/>
                              <s:convertEntity />
                              <a4j:support event="onchange" reRender="dbDriverid" />
                          </h:selectOneMenu>
      .............
      
      <h:selectOneMenu id="dbDriverid" styleClass="LoginLangCombo" value="#{dbparams.dbDriver}">                        
                              <s:selectItems value="#{dbDrivers.resultList}" var="driver" label="#{driver.drivername}" noSelectionLabel="Please Select DataBase ... "/>
                              <s:convertEntity />
                          </h:selectOneMenu>
      


      how i can filter second component by first ?
      here is my entities



      @Entity
      @Table(name = "DB_VENDOR",schema="JITS")
      public class DbVendor implements Serializable {
      private static final long serialVersionUID = 1L;
      private BigDecimal id;
      private String dbvendorname;
      private Collection<DbDriver> dbDrivers;
      // .... setters and getters
      }
      


      and


      @Entity
      @Table(name = "DB_DRIVER",schema="JITS")
      public class DbDriver implements Serializable {
      private static final long serialVersionUID = 1L;
      private BigDecimal id;
      private String dbdrivername;
      private DbVendor vendor;
      // .... setters and getters
      }
      


      and my components.xml looks like :


      <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" />
         
         <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 where v.dbVendorId = #{dbparams.dbVendor} " />
      
      



      what is incorrect into my example ?
      is there any example about it ?


      i saw seam production example, they did what i need :
      http://www.partsallover.com.au/home.seam?cid=71128



      any idea will be appreciated.


      Regards


      Paata.

        • 1. Re: Fill SelectOnemenu filtered by another one (using a4j)
          damianharvey.damianharvey.gmail.com

          Show us your dbparams Bean.


          My guess would be that it isn't scoped widely enough to maintain the value of dbVendor for when the dbDrivers are refreshed. Do you have something like @Scope(ScopeType.CONVERSATION) in your Bean and a <begin-conversation/> in your page.xml?


          Cheers,


          Damian.

          • 2. Re: Fill SelectOnemenu filtered by another one (using a4j)
            mokua

            and try setting bypassUpdates to false
            on the a4j support tag

            • 3. Re: Fill SelectOnemenu filtered by another one (using a4j)
              paata.paatal.magtigsm.ge

              Hi Richard.


              i set bypassUpdates to false on the a4j support tag but it did not change anything.


              Hi Damian.
              here is my dbparams Bean:


              @Name("dbparams")
              @Scope(ScopeType.CONVERSATION)
              public class DBParams {
                  private String dbName;
                  private DbDriver dbDriver;
                  private DbVendor dbVendor;
                  // getters and setters
              }
              


              and my pages.xml looks like :


              <page view-id="/db/configwizard/dbconfwstep1.xhtml">
                      <begin-conversation/>
              </page>
              




              i got this exception :



              SEVERE: Error Rendering View[/db/configwizard/dbconfig.xhtml]
              javax.faces.FacesException: javax.el.ELException: /db/configwizard/dbconfwstep1.xhtml @53,160 value="#{dbDrivers.resultList}": Error reading 'resultList' on type org.jboss.seam.framework.EntityQuery_$$_javassist_4


              ...............




              Caused by: java.lang.IllegalArgumentException: org.hibernate.QueryException: Not all named parameters have been set: [el1] [select v from DbDriver v where v.dbVendorId = :el1 ]




              Great Thanks for your posts.


              Regards


              Paata

              • 4. Re: Fill SelectOnemenu filtered by another one (using a4j)
                mokua

                It appears like the
                dbparams.dbVendor
                is not set,try including the
                first
                selectOneMenu
                inside an 'a4j:region' so that the set value can be submitted.
                And don't forget setting the bypassUpdates to false


                Cheers
                Richard

                • 5. Re: Fill SelectOnemenu filtered by another one (using a4j)
                  paata.paatal.magtigsm.ge

                  hi again Richard.


                  Great thanks for your quick reply.


                  now my UI looks like :


                  <a4j:region>
                                          <h:selectOneMenu id="dbType" styleClass="LoginLangCombo" value="#{dbparams.dbVendor}">                        
                                              <s:selectItems value="#{dbVendors.resultList}" var="vendor" label="#{vendor.dbvendorname}" noSelectionLabel="Please Select Vendor ... "/>
                                              <s:convertEntity />
                                              <a4j:support event="onchange" reRender="dbDriverid" bypassUpdates="false"/>
                                          </h:selectOneMenu>
                                      </a4j:region>
                  



                  here is both components which you told me : region and bypassUpdates where value is false.



                  Regards


                  Paata.

                  • 6. Re: Fill SelectOnemenu filtered by another one (using a4j)
                    mokua

                    sorry for taking long,


                    Yep, that looks right.

                    • 7. Re: Fill SelectOnemenu filtered by another one (using a4j)
                      paata.paatal.magtigsm.ge

                      i tried to print dbVendor field into dbparams by tehere is null.


                      DBParams.java


                          public DbVendor getDbVendor() {
                              System.out.println("Get. dbVendor = " + dbVendor);
                              return dbVendor;
                          }
                      
                          public void setDbVendor(DbVendor dbVendor) {
                              System.out.println("Set. dbVendor = " + dbVendor);
                              this.dbVendor = dbVendor;
                          }
                      


                      but i got Get. dbVendor = null in 10 times becouse i have 10 record into dbvendor table on database.


                      you ara right dbVendor is not set.



                      Regards.


                      Paata.

                      • 8. Re: Fill SelectOnemenu filtered by another one (using a4j)
                        paata.paatal.magtigsm.ge

                        fixed.


                        i resolve this problem by framework:restrictions attribute.


                        now my ejb-ql looks like :


                        <framework:entity-query name="dbDrivers" ejbql="select v from DbDriver v">
                               <framework:restrictions>
                                   <value>v.dbVendor = #{dbparams.dbVendor}</value>
                               </framework:restrictions>
                           </framework:entity-query>
                        




                        Greate Thanks.

                        • 9. Re: Fill SelectOnemenu filtered by another one (using a4j)
                          paata.paatal.magtigsm.ge

                          fixed.


                          i resolve this problem by framework:restrictions attribute.


                          now my ejb-ql looks like :


                          <framework:entity-query name="dbDrivers" ejbql="select v from DbDriver v">
                                 <framework:restrictions>
                                     <value>v.dbVendor = #{dbparams.dbVendor}</value>
                                 </framework:restrictions>
                             </framework:entity-query>
                          



                          Greate Thanks.

                          • 10. Re: Fill SelectOnemenu filtered by another one (using a4j)
                            visumagic

                            Hi Paata,


                            I do have same kind of requirement.
                            But I'm not able to get the solution. Here Im facing



                            06:49:35,406 INFO  [lifecycle] WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
                            sourceId=user:atestForm:j_id151:col2[severity=(ERROR 2), summary=(value is not valid), detail=(value is not valid)]



                            And my query is



                             <framework:restrictions>
                                       <value>college.university.id = #{ClassroomSearch.university.id}</value>
                                   </framework:restrictions>
                                
                                 </framework:entity-query>
                                <factory name="collegeListUnderUniversityList" value="#{collegeListUnderUniversityQuery.resultList}"  />
                            


                            When ever i hard code ClassroomSearch.university.id to 1 ,my the combobox is working fine, other wise it's failing with the above error.


                            please help me


                            thanks
                            raghu

                            • 11. Re: Fill SelectOnemenu filtered by another one (using a4j)
                              visumagic

                              Hi


                              Please post some working sample , It's really taking more time to fix this. even though i dont have confidence that I can fix this


                              please post  code fragments , it will be useful to lot of people like me...


                              thanks
                              raghu