title: Richfaces 3.3/JBoss Seam 2.2. Dynamic loading of multiple combo boxes
body: <p>I have three combo boxes. The first one is populated with values. When I select a value from it, the second must be updated. After that, when I select a value from the second combo, the third should be populated. I know that this is already communicated, but with two combos. With more than two it is not working. Could you please tell me what I didn't do properly?</p>
  
  <p>Here is the view:</p>
  
  <pre><code>&lt;h:form&gt;
      &lt;h:panelGrid columns="2"&gt;        
          &lt;h:outputText value="Choose the produce type:"/&gt;
  
          &lt;h:selectOneMenu id="firstList"
                              value="#{userBean.firstItem}"                
                              valueChangeListener="#{userBean.valueChanged}"&gt;
              &lt;f:selectItems value="#{userBean.firstList}"
                             var="element"
                             itemLabel="#{element.label}"
                             itemValue="#{element.value}" /&gt;
                  &lt;a4j:support reRender="outputPanel"
                               event="onchange"                                                                  
                               ajaxSingle="true"
                               bypassUpdates="false" /&gt;                
          &lt;/h:selectOneMenu&gt;
  
          &lt;a4j:outputPanel id="outputPanel"&gt;
              &lt;h:selectOneMenu value="#{userBean.secondItem}"                
                               valueChangeListener="#{userBean.valueChanged}"&gt;
              &lt;f:selectItems value="#{userBean.secondList}"
                             var="element"
                             itemLabel="#{element.label}"
                             itemValue="#{element.value}" /&gt;                    
                      &lt;a4j:support reRender="outputPanel"
                               event="onchange"                                                                  
                               ajaxSingle="true"
                               bypassUpdates="false" /&gt;                                                 
              &lt;/h:selectOneMenu&gt;
  
              &lt;h:selectOneMenu value="#{userBean.thirdItem}"                
                               valueChangeListener="#{userBean.valueChanged}"&gt;
              &lt;f:selectItems value="#{userBean.thirdList}"
                             var="element"
                             itemLabel="#{element.label}"
                             itemValue="#{element.value}" /&gt;                                                 
              &lt;/h:selectOneMenu&gt;                
          &lt;/a4j:outputPanel&gt;
  
      &lt;/h:panelGrid&gt;
  &lt;/h:form&gt;
  </code></pre>
  
  <p>This is the Bean (this is a sample code without any meaningful sence):</p>
  
  <pre><code>@Name("userBean")
  public class UserBean
  {
  @Logger private Log log;
  
  @In StatusMessages statusMessages;
  
  private String firstItem="";
  private String secondItem="";
  private String thirdItem="";
  public List&lt;SelectItem&gt; firstList = new ArrayList&lt;SelectItem&gt;(); 
  public List&lt;SelectItem&gt; secondList = new ArrayList&lt;SelectItem&gt;();
  public List&lt;SelectItem&gt; thirdList = new ArrayList&lt;SelectItem&gt;();
  private static final String [] FRUITS = {"Banana", "Cranberry", "Blueberry", "Orange"};
  private static final String [] VEGETABLES = {"Potatoes", "Broccoli", "Garlic", "Carrot"};
  private static final String [] GIRLS = {"Victoria", "Nana", "Etc.."};
  
  public UserBean() {
      SelectItem item = new SelectItem("fruits", "Fruits");
      firstList.add(item);
      item = new SelectItem("vegetables", "Vegetables");
      firstList.add(item);
      item = new SelectItem("girls", "Girls");
      firstList.add(item);
      for (int i = 0; i &lt; FRUITS.length; i++) {
          item = new SelectItem(FRUITS[i]);
      }
  }
  
  public List&lt;SelectItem&gt; getFirstList() {
      return firstList;
  }
  
  public List&lt;SelectItem&gt; getSecondList() {
      return secondList;
  }
  
  public List&lt;SelectItem&gt; getThirdList() {
      return thirdList;
  }
  
  public static String[] getFRUITS() {
      return FRUITS;
  }
  
  public static String[] getVEGETABLES() {
      return VEGETABLES;
  }
  
  public static String[] getGIRLS() {
      return GIRLS;
  }
  
  public void valueChanged(ValueChangeEvent event){
      String[] currentItems;
      String id = ((HtmlSelectOneMenu)event.getSource()).getId();
      if (id.equals("firstList")) {            
          currentItems = FRUITS;
  
          for (int i = 0; i &lt; currentItems.length; i++) {
              SelectItem item = new SelectItem(currentItems[i]);
              secondList.add(item);
          }
  
          thirdList.clear();
      } else {
          currentItems = GIRLS;
  
          for (int i = 0; i &lt; currentItems.length; i++) {
              SelectItem item = new SelectItem(currentItems[i]);
              thirdList.add(item);
          }
      }  
  }
  
  public String getFirstItem() {
      return firstItem;
  }
  
  
  public void setFirstItem(String firstItemArg) {
      firstItem = firstItemArg;
  }
  
  
  public String getSecondItem() {
      return secondItem;
  }
  
  
  public void setSecondItem(String secondItemArg) {
      secondItem = secondItemArg;
  }
  
  public String getThirdItem() {
      return thirdItem;
  }
  
  
  public void setThirdItem(String thirdItemArg) {
      thirdItem = thirdItemArg;
  } 
  </code></pre>
  
  <p>The problem is that when I select a value from the second combo box (values of which were loaded dynamically), the page is reloaded (instead of ajax request being executed) and I have exception: </p>
  
  <p>Exception during request processing:
  Caused by javax.servlet.ServletException with message: "java.util.NoSuchElementException"</p>
  
  <p>The second list is successfully updated from the first list, but after that something is wrong.</p>
  
  <p>Thanks in advance!
  Cheers!</p>