0 Replies Latest reply on Feb 12, 2010 3:02 AM by haris gx

    ManyListBox is not saving data after rerender

    haris gx Newbie

      I was working on a feature in which a selection on a list box will filter the data in the other list box.Then I select the second list box items and tries to get the data, it fails.


      Used seam 2.0 and jboss 4.2.2GA


      The code will be similar to the following


      xhtml code:


      <s:decorate id="fId" template="../layout/template.xhtml">
          <h:selectManyListbox value="#{form.selectedItemsInListA}">
               <f:selectItems value="#{form.optionsInListA}" />
               <a:support actionListener="#{form.fillItemsInListB(form.selectedItemsInListA)}"
                              event="onchange"   reRender="listBId"/>
           </h:selectManyListbox>
      </s:decorate>
      
      <s:decorate id="gId" template="../layout/template.xhtml">
           <h:selectManyListbox id="listBId" style="width:150px"
               value="#{form.selectedListBItems}">
                <f:selectItems value="#{form.optionsInListB}" />
          </h:selectManyListbox>
      </s:decorate>
      
      Form.java
      
      @Name("form")
      @Scope(ScopeType.CONVERSATION)
      public class Form {
           List<SelectItem> optionsInListA;
           List<SelectItem> optionsInListB;
           
           List<String> selectedItemsInListA;
           List<String> selectedItemsInListB;
           
           public Form(){
                optionsInListA = new ArrayList<SelectItem>();
                optionsInListA.add(new SelectItem("1","A"));
                optionsInListA.add(new SelectItem("2","B"));
           }
           
           public void fillItemsInListB(List<String> itemsSelected){
                optionsInListB = new ArrayList<SelectItem>();
                for(String str: itemsSelected){
                     if("1".equals(str)){
                          optionsInListB.add(new SelectItem("1","Australia"));
                     }
                     if("2".equals(str)){
                          optionsInListB.add(new SelectItem("2","Bulgaria"));
                     }
                }
                
           }     
           
           public List<String> getSelectedItemsInListA(){
                return this.selectedItemsInListA;
           }
           public void setSelectedItemsInListA(List<String> selectedItemsInListA){
                this.selectedItemsInListA=selectedItemsInListA;
           }
           
           public List<String> getSelectedItemsInListB(){
                return this.selectedItemsInListB;
           }
           public void setSelectedItemsInListB(List<String> selectedItemsInListB){
                this.selectedItemsInListB=selectedItemsInListB;
           }
      
              public List<SelectItem> getOptionsInListA(){
                return this.optionsInListA;
           }
           public void setOptionsInListA(List<SelectItem> optionsInListA){
                this.optionsInListA=optionsInListA;
           }
              public List<SelectItem> getOptionsInListB(){
                return this.optionsInListB;
           }
           public void setOptionsInListB(List<SelectItem> optionsInListB){
                this.optionsInListB=optionsInListB;
           }
      
      }
      
      
      



      Here I am able to populate both list boxes.When i select an option in list A, the respective data is shown in list b dynamically using the ajax call. But when I try to save the form after selecting an option in list B,(here no events for listbox), the form.selectedListBItems associated with the value of listbox is empty in the backing bean. Anyone have any idea about why this happens when rerender is done?