0

Hi I have the following snipples:

SimController:

 private static List<SelectItem> userList;

 public List<SelectItem> getUserList(String Id) {
    try {
        userList = new ArrayList<SelectItem>();
        userList = PDAO.getUserList(Id);
    } catch (ClassNotFoundException | SQLException e) {
        e.printStackTrace();
    }

    return userList;
}

public void setUserList(List<SelectItem> userlist){
    this.userlist = userlist;
}

PDAO:

 public static List<SelectItem> getUserList(String Id) throws ClassNotFoundException, SQLException {
    String sqlCmdName = "sql_get_other_users";
    String sql = getSql(sqlCmdName);
    sql = Util.prepareSqlExt(sql, new String[] { Id });
    return (List<SelectItem>) buildResultSet(new ConverterToUserList(), sqlCmdName, sql);
}


 class ConverterToUserList implements ResultSetConverterInterface {

public Object convertResultSet(ResultSet resultSet) throws SQLException {
    List<SelectItem> userList = new ArrayList<SelectItem>();
    while (resultSet.next()) {
        userList.add(new SelectItem(resultSet.getString(1)));

    }
    if (userList.isEmpty())
        return null;
    return userList;
}
 }

Html:

 <t:div styleClass="#{SimController.simTabName=='SIMULATION_USERS'?'tabPaneActive':'tabPane'}">
                <h:commandButton style="width: 120px !important;" id="TabId3" value="#{messages.tab_other_user}" action="#{SimController.goOtherUsers}" immediate="true" onclick="wait2();">
                    <f:param name="id" value="#{pSimController.details.Id}" />
                </h:commandButton>
            </t:div>



 <h:selectOneMenu styleClass="linkButtons" value="SimController.userListtry"  onchange="document.getElementById('SimFormId:mdsTabId3').click();">
    <f:selectItem itemValue="" itemLabel="-" />
    <f:selectItems value="#{SimController.userList}" />
</h:selectOneMenu>

The values I get when I print out the userlist at the latest possible moment i.e. before they are past the the html is:

  [javax.faces.model.SelectItem@13a89211, javax.faces.model.SelectItem@46c92ce7, javax.faces.model.SelectItem@7dbe8fcb, javax.faces.model.SelectItem@4a3d1f6a, javax.faces.model.SelectItem@1d522426]

which to me looks fine but I always get the following message

 org.apache.myfaces.shared.util.SelectItemsIterator hasNext
 WARNING: ValueExpression #{SimController.userList} of UISelectItems with component-path {Component-Path : [Class: javax.faces.component.UIViewRoot,ViewId: /pages/pSim.xhtml][Class: org.apache.myfaces.custom.document.Document,Id: appId][Class: org.apache.myfaces.custom.document.DocumentBody,Id: appBodyId][Class: javax.faces.component.html.HtmlPanelGrid,Id: j_id_t][Class: javax.faces.component.html.HtmlPanelGroup,Id: j_id_1u][Class: javax.faces.component.html.HtmlPanelGrid,Id: j_id_1v][Class: javax.faces.component.html.HtmlPanelGroup,Id: j_id_1z][Class: javax.faces.component.html.HtmlPanelGrid,Id: j_id_20][Class: javax.faces.component.html.HtmlSelectOneMenu,Id: j_id_28][Class: javax.faces.component.UISelectItems,Id: j_id_2a]} does not reference an Object of type SelectItem, array, Iterable or Map, but of type: null

 org.apache.myfaces.shared.renderkit.html.HtmlGridRendererBase renderChildren
 WARNING: PanelGrid {Component-Path : [Class: javax.faces.component.UIViewRoot,ViewId: /pages/pSim.xhtml][Class: org.apache.myfaces.custom.document.Document,Id: appId][Class: org.apache.myfaces.custom.document.DocumentBody,Id: appBodyId][Class: javax.faces.component.html.HtmlPanelGrid,Id: j_id_t][Class: javax.faces.component.html.HtmlPanelGroup,Id: j_id_1u][Class: javax.faces.component.html.HtmlPanelGrid,Id: j_id_1v][Class: javax.faces.component.html.HtmlPanelGroup,Id: j_id_1z][Class: javax.faces.component.html.HtmlPanelGrid,Id: j_id_20] Location: /pages/planung/inc/buttonStripBottomSimul.xhtml at line 3 and column 55} has not enough children. Child count should be a multiple of the columns attribute. 

The menu is shown on the html page but it is empty.

Any idea on why this is the case??

Thanks for all your help.

Viking

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Viking
  • 73
  • 1
  • 9
  • where are you printing the list? I don't see code for that. Is it because SimController don't have a getter for userList? – Ankush G Aug 16 '17 at 14:06
  • It says getUserList in SimController above... am I missing something? – Viking Aug 16 '17 at 14:09
  • 1
    Getters don't take method arguments. You have a `public List getUserList(String Id)`, but you should have a `public List getUserList()` method. – BalusC Aug 16 '17 at 14:15
  • @BalusC Wow thanks.. didn't know you can't do that.. It works now. Thanks – Viking Aug 16 '17 at 14:23

2 Answers2

0

As @balusc already pointed out, try <f:selectItems value="#{SimController.getUserList(id)}" from the facelet, if you can access the id, which I guess would be #{pSimController.details.Id}.

mrod
  • 772
  • 1
  • 6
  • 20
0

Since I can't close the question from a comment... here is credit to @BalusC

Getters don't take method arguments. You have a public List getUserList(String Id), but you should have a public List getUserList() method. – BalusC 7 mins ago

Thanks for your help

Viking
  • 73
  • 1
  • 9