3 Replies Latest reply on Mar 18, 2008 11:54 AM by mars1412

    Dropdown list value is null

    ever

      Hello I recieve a null value from the jsf view at my session bean. Maybe it is just something tiny but cant see the neadle in the hay..


      best regards !
      JSF code



      <rich:panelBar id="pB_selectSamples"  width="530">
                              <ui:repeat value="#{category}" var="cat">                 
                                      <rich:panelBarItem id="pbi_#{cat.id}" label=">>  #{cat.name}">                      
                                                      <a4j:form ajaxSubmit="true" reRender="qty_column">
                                                      <h:dataTable id="dT_#{cat.id}" var="product" value="#{cat.children}">     
      <!-- QTY -->                                              
                                                   <h:column id="qty_column" rendered="#{product.maxSamples gt 0}">                                             
                                                              <f:facet name="header">
                                                                      <h:outputText value="Quantity" />
                                                              </f:facet>                                                        
                                                              <h:selectOneMenu id="SOM_qty" value ="#{order.count}" >
                                                                      <s:selectItems value="#{product.sampleMaxList}" var="count"
                                                                              label="#{count}" noSelectionLabel="Qty." hideNoSelectionLabel = "false"/>                                                                                                                                                                                    
                                                              </h:selectOneMenu>
                                                              
                                                              <h:commandLink value="Add"  action="#{order.add(product)}" >                                                              
                                                              </h:commandLink>
                                                      </h:column>
                                      </h:dataTable>
                              </a4j:form>
                                               
                      </rich:panelBarItem>
              </ui:repeat>                      
      </rich:panelBar>




      if the user clicks on the add button everything works fine ther right product gets submitted but the "#{order.count}" is 0 Zero


      @Stateful
      @Scope(ScopeType.SESSION)
      @Name("order")
      public class OrderBean implements Order  {
              
          @Logger private Log log;
              
          @In FacesMessages facesMessages;
          
          @PersistenceContext EntityManager em;
             
          // @In(required=false) did try it with no success
          private String  count ;
      
       public void add(Product product){
          log.info("add was called
       }
      
              public String getCount() {
                      return count;
              }
      
      
      
              public void setCount(String count) {
                      this.count = count;
              }
      
      



      I did try all kind of possibilities but everything without a success, does it maybe hase something to do with the stacking of the loops inside each other?


        • 1. Re: Dropdown list value is null

          I think reading
          c:foreach-vs-ui:repeat
          should help you understand what's going on.

          • 2. Re: Dropdown list value is null
            ever

            Ok I read it.
            So i reduced my situation to following starting with only one DataTable.




            @Stateful
            @Scope(ScopeType.SESSION)
            @Name("order")
            public class OrderBean implements Order  {
                    
                @Logger private Log log;
                    
                @In FacesMessages facesMessages;
                
                @PersistenceContext EntityManager em;
                   
                @In(required=false) <<-- Now injection
                private String  count ;
            
                @DataModel
                List<Product> products;
            
             public void add(Product product){
                log.info("add was called");
             }
            
            
            
            
            <h:messages styleClass="message" />
                            <a4j:form reRender="qty_column" ajaxSubmit="true">
                                    <h:dataTable id="dT_product" var="product" value="#{products}">
            
            
                                            <h:column id="qty_column" rendered="#{product.maxSamples gt 0}">
                                                    <f:facet name="header">
                                                            <h:outputText value="Quantity" />
                                                    </f:facet>
            
                                                    <h:selectOneMenu id="SOM_qty" value="#{count}">
                                                            <s:selectItems value="#{product.sampleMaxList}" var="c"
                                                                    label="#{c}" noSelectionLabel="Qty." hideNoSelectionLabel="false" />
                                                    </h:selectOneMenu>
            
                                                    <h:commandButton value="Add" action="#{order.add(product)}"
                                                            id="addtocart">
                                                    </h:commandButton>
            
                                    </h:column>
            
                            </h:dataTable>
                            </a4j:form>
            


            If i click on the add button the product gets submitted to the bean but not the value in selectItems (fyi #{c} is of type string)



            so i have a list of  5 entries with 5 drop down boxes


            if i select first one with propper value and click the add button the product is submitted but not the value form the selectOneMenu
            only if I choose from the last dropdown box of the list a value and click the coresponding button only then the value from the dropdown list gets submitted to the bean


            I found an article in the wiki whih is abut the same problem My Link
            i stick right to the solution but it doesnt work for me



            regards

            • 3. Re: Dropdown list value is null

              hmm.. I don't understand if your code works at all.
              you use


              #{count}



              in your page. What does it refer to?
              do you mean


              #{order.count}




              anyway: here is an excellent article about using-datatables.