嗨,我有以下snipples: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是:
[[email protected], [email protected], [email protected], [email protected], [email protected]]
這對我來說看起來不錯,但我總是得到以下信息
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頁面上顯示的卻是空。
任何想法,爲什麼這是這種情況?
感謝您的幫助。
海盜
您在哪裏打印清單?我沒有看到代碼。 是因爲SimController對於userList沒有getter? – vvtx
它說上面的SimController中的getUserList ...我錯過了什麼嗎? – Viking
Getters不採取方法論據。你有一個'public List getUserList(String Id)',但你應該有一個'public List getUserList()'方法。 –
BalusC