我正在使用JSF標記h:selectManyListbox在JSP中顯示來自bean的項目列表。JSF selectManyListbox顯示值綁定錯誤
<h:selectManyListbox value="#{settingsBean.statusIds}" style="width: 100%; height: 200px;">
<f:selectItem value="#{settingsBean.statusItems}" />
</h:selectManyListbox>
的statusItems對象是在下面bean類中定義:
:SettingsBean.java
public class SettingsBean {
private List<String> statusIds;
private List<SelectItem> statusItems;
public SettingsBean() {
initStatus();
}
private void initStatus() {
statusItems = new ArrayList<SelectItem>();
statusItems.add(new SelectItem("v1", "lbl1"));
statusItems.add(new SelectItem("v2", "lbl2"));
statusItems.add(new SelectItem("v3", "lbl3"));
}
public ArrayList getStatusItems(){
return getStatusItemsList(false);
}
@SuppressWarnings("unchecked")
private ArrayList getStatusItemsList(boolean selected) {
ArrayList ids = new ArrayList();
if (!selected) {
boolean inSelIds = false;
for (int i=0; i < statusItems.size(); i++) {
inSelIds = false;
SelectItem item = (SelectItem)statusItems.get(i);
if (selected==inSelIds) {
String text = item.getLabel();
//ids.add(text);
ids.add(new SelectItem(item.getValue(), text));
}
}
}
return ids;
}
}
但我這個加載時收到錯誤消息
HTTP Status 500 - java.lang.IllegalArgumentException: Value binding '#{settingsBean.statusItems}' of UISelectItem : {Component-Path : [Class: javax.faces.component.UIViewRoot,ViewId: /jsp/Settings.jsp][Class: javax.faces.component.html.HtmlSelectManyListbox,Id: _id3][Class: javax.faces.component.UISelectItem,Id: _id4]} does not reference an Object of type SelectItem
我應該丟失什麼或導致此問題?感謝您的幫助
這是一個類型,你正在使用的數據類型,而不是其他 –