2

我正在使用 JSF 标记 h:selectOneMenu 作为下拉列表。

<h:selectOneMenu id="subscriberName" value="#{manageSubscriberInformation.subscriberName}" 
    <f:selectItem itemValue="" itemLabel="" />                            
    <f:selectItems value="#{manageSubscriberInformation.subList}" />
</h:selectOneMenu> 

subList 对象是我在我的 bean 类中使用 getter 和 setter 定义的列表。在我的 servlet 的 init 方法中,我用一些值填充列表。但是当我加载页面时,我收到以下错误:

java.lang.IllegalArgumentException: Collection referenced by UISelectItems with binding '#{manageSubscriberInformation.subList}' and Component-Path : {Component-Path : [Class: javax.faces.component.UIViewRoot,ViewId: /jsp/manageSubscriber.jsp][Class: javax.faces.component.UINamingContainer,Id: body][Class: javax.faces.component.html.HtmlForm,Id: c][Class: javax.faces.component.html.HtmlSelectOneMenu,Id: subscriberName][Class: javax.faces.component.UISelectItems,Id: _idJsp143]} does not contain Objects of type SelectItem

无法理解导致问题的原因。

4

1 回答 1

2

例外是不言自明的。

java.lang.IllegalArgumentException:UISelectItems (...) 引用的集合不包含 SelectItem 类型的对象

必须#{manageSubscriberInformation.subList}返回一个List<SelectItem>SelectItem[]哪里SelectItemjavax.faces.model.SelectItem

仅从 JSF 2.0 开始,不再需要专门为SelectItem.

也可以看看:

于 2012-03-08T00:00:07.940 回答