title: Create JSF datatable with selectonemenu and fill its data from database
body: <p>I'm trying to create a jsf datatable with select one menu and to fill it from database but can't get it work here is my JSF code:</p>
  
  <pre><code>  &lt;ice:dataTable id="dataTable1" value="#{Page1.users}" var="users"&gt;
                          &lt;ice:column id="column2"&gt;
  
                             &lt;ice:outputText id="userID" value="users.userId"/&gt;
                              &lt;f:facet name="header"&gt;
                                  &lt;ice:outputText id="outputText1" value="Table_Column1"/&gt;
                              &lt;/f:facet&gt;
  
                          &lt;/ice:column&gt;
  
                          &lt;ice:column id="column2"&gt;
  
  
                              &lt;f:facet name="header"&gt;
                                  &lt;ice:outputText id="outputText4" value="Table_Column2"/&gt;
                              &lt;/f:facet&gt;
                              &lt;ice:selectOneMenu id="users" value="#{Page1.selectedUser}" &gt;
                              &lt;f:selectItems value="#{users.screenName}"/&gt;
  
                              &lt;/ice:selectOneMenu&gt;
                          &lt;/ice:column&gt;
  
                      &lt;/ice:dataTable&gt;
  </code></pre>
  
  <p>Page1 code:</p>
  
  <pre><code> private ArrayList&lt;UserTable&gt; users=new ArrayList&lt;UserTable&gt;();
  
      public ArrayList&lt;UserTable&gt; getUsers() {
  
          if(users==null){
              UserTable u1=new UserTable(1);
              users.add(u1);
              u1=new UserTable(2);
              users.add(u1);
  
          }
          return users;
      }
      private String selectedUser;
  
      public String getSelectedUser() {
          return selectedUser;
      }
  
      public void setSelectedUser(String selectedUser) {
          this.selectedUser = selectedUser;
      }
  </code></pre>
  
  <p>and Finally userTable code:</p>
  
  <pre><code>public class UserTable {
      private long userId;
      private Option[] screenName;
  
      public UserTable(long userId) {
          this.userId = userId;
      }
  
      public Option[] getScreenName() {
          if(screenName==null){
          buildScreenNameOptions();
          }
          return screenName;
      }
  
      public void setScreenName(Option[] screenName) {
          this.screenName = screenName;
      }
  
  
      public long getUserId() {
          return userId;
      }
  
      public void setUserId(long userId) {
          this.userId = userId;
      }
  
      private void buildScreenNameOptions() {
      List&lt;String&gt; screenNameList = null;
      try{
          Session session = NewHibernateUtil.getSessionFactory().getCurrentSession();
          Transaction tx = session.beginTransaction();
          Query q = session.createQuery("Select screenName from User");
          screenNameList = (List&lt;String&gt;) q.list();
  
      } catch(Exception e) {
          e.printStackTrace();
      }
  
      screenName = new Option[screenNameList.size()];
      int i=0;
      for(String name : screenNameList) {
          Option opt = new Option(name);
         screenName[i++] = opt;
      }
  }
  
  
  }
  </code></pre>
  
  <p>So what's going wrong?</p>
  
  <p>Thanks</p>