selectOneMenu不显示值

时间:2017-08-16 13:52:16

标签: jsf myfaces selectonemenu

您好我有以下信息:

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>

我在最近可能的时刻打印用户列表时得到的值,即在它们超过html之前:

  [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]

对我来说看起来很好,但我总是收到以下消息

 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. 

菜单显示在html页面上,但它是空的。

任何想法为什么会这样?

感谢您的帮助。

维京

2 个答案:

答案 0 :(得分:0)

正如@balusc已经指出的那样,如果你可以访问IQueryable<BasePeople> basePeople; if (teamType == "A") basePeople = context.PeopleExtendedInfoA; else basePeople = context.PeopleExtendedInfoB; ,我可以从小面孔中试用<f:selectItems value="#{SimController.getUserList(id)}",我想这将是id

答案 1 :(得分:0)

因为我无法从评论中结束这个问题......这里归功于@BalusC

Getters不接受方法论证。您有一个公共List getUserList(String Id),但您应该有一个公共List getUserList()方法。 - BalusC 7分钟前

感谢您的帮助