title: java.lang.ClassCastException: java.util.ArrayList cannot be cast to javax.faces.model.SelectItem
body: <p>I am trying to make my dropdown dynamic and below is the code and exception i am getting. Please help me out</p>
  
  <p>bean:</p>
  
  <pre><code>    private String dropDownValue;
      List&lt;SelectItem&gt; testDropDown = new ArrayList&lt;SelectItem&gt;();
      List&lt;SelectItem&gt; testDropDownTwo = new ArrayList&lt;SelectItem&gt;();
  
      public String getDropDownValue() {
          return dropDownValue;
      }
  
  
      public void setDropDownValue(String dropDownValue) {
          this.dropDownValue = dropDownValue;
      }
  
  
      public List&lt;SelectItem&gt; getTestDropDown() {
          testDropDown.add(new SelectItem("One"));
          testDropDown.add(new SelectItem("Two"));
          testDropDown.add(new SelectItem("Three"));
          testDropDown.add(new SelectItem("Four"));
          return testDropDown;
      }
  </code></pre>
  
  <p>XHtml Code:</p>
  
  <pre><code>&lt;h:selectOneMenu value="#{loginBean.dropDownValue}"&gt;
      &lt;f:selectItem value="#{loginBean.testDropDown}" /&gt;
  &lt;/h:selectOneMenu&gt;
  </code></pre>
  
  <p>Exception:</p>
  
  <p>exception </p>
  
  <pre><code>    javax.servlet.ServletException: java.util.ArrayList cannot be cast to javax.faces.model.SelectItem
      javax.faces.webapp.FacesServlet.service(FacesServlet.java:321)
  
      root cause 
      java.lang.ClassCastException: java.util.ArrayList cannot be cast to javax.faces.model.SelectItem
      com.sun.faces.renderkit.SelectItemsIterator.initializeItems(SelectItemsIterator.java:185)               com.sun.faces.renderkit.SelectItemsIterator.hasNext(SelectItemsIterator.java:131)
      com.sun.faces.renderkit.html_basic.MenuRenderer.renderOptions(MenuRenderer.java:758)
      com.sun.faces.renderkit.html_basic.MenuRenderer.renderSelect(MenuRenderer.java:840)
      com.sun.faces.renderkit.html_basic.MenuRenderer.encodeEnd(MenuRenderer.java:294)
      javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:879)
      javax.faces.component.UIComponent.encodeAll(UIComponent.java:1650)
  </code></pre>
  
  <p>Some classcast exception is happening. but i am sending the ArrayList of SelectItem to the list</p>
  
  <p>if i change the Value attribute in selectItem tag to itemValue it is not trowing a exception but i am not getting any value i am getting the object names as in the drop down in a single list</p>