Java 无法在icefaces(jsf)xhtml页面上检索arraylist元素

Java 无法在icefaces(jsf)xhtml页面上检索arraylist元素,java,jsf,icefaces,Java,Jsf,Icefaces,我的页面上有一个HTML表,并试图用托管bean中的一些数据填充它,我的xhtml页面如下所示: <ice:panelGrid columns="2"> <ice:panelGrid> <ice:outputText value="Properties:" style="text-align:left;font-size:20px;"></ice:outputText>

我的页面上有一个HTML表,并试图用托管bean中的一些数据填充它,我的xhtml页面如下所示:

       <ice:panelGrid columns="2">
            <ice:panelGrid>
                <ice:outputText value="Properties:" style="text-align:left;font-size:20px;"></ice:outputText>
                <ice:selectManyListbox id="CriteriaListbox" style="width: 200px; height: 250px; " partialSubmit="true">
                 <p:selectItem value="#{beanInfo.properties}"/>
                </ice:selectManyListbox>
            </ice:panelGrid>
      </ice:panelGrid>
public ArrayList<String> getProperties()
{
    return properties;
}
我不熟悉jsf和icefaces,所以不确定这里的问题是什么。有什么建议吗

更新

因此,我的表中没有任何内容,但我得到java.util.ArrayList不能转换为javaax.faces.model.SelectItem异常

更新2

如果有任何建议,这是我在将我的JSF版本从Mojarra-2.0.3更新到Mojarra-2.1.7之后得到的一个例外

Error Rendering View[/admin/Template.xhtml]: java.lang.ClassCastException: java.lang.String cannot be cast to javax.faces.model.SelectItem
    at com.icesoft.faces.renderkit.dom_html_basic.MenuRenderer.countSelectOptionsRecursive(MenuRenderer.java:440) [:]
    at com.icesoft.faces.renderkit.dom_html_basic.MenuRenderer.renderSelect(MenuRenderer.java:366) [:]
    at com.icesoft.faces.renderkit.dom_html_basic.MenuRenderer.encodeEnd(MenuRenderer.java:108) [:]
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875) [:2.1.7-SNAPSHOT]
    at com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer.encodeParentAndChildren(DomBasicRenderer.java:359) [:]
    at com.icesoft.faces.renderkit.dom_html_basic.GridRenderer.encodeChildren(GridRenderer.java:197) [:]
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845) [:2.1.7-SNAPSHOT]
    at com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer.encodeParentAndChildren(DomBasicRenderer.java:347) [:]
    at com.icesoft.faces.renderkit.dom_html_basic.GridRenderer.encodeChildren(GridRenderer.java:197) [:]
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845) [:2.1.7-SNAPSHOT]
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779) [:2.1.7-SNAPSHOT]
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782) [:2.1.7-SNAPSHOT]
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782) [:2.1.7-SNAPSHOT]
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782) [:2.1.7-SNAPSHOT]
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:402) [:2.1.7-SNAPSHOT]
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125) [:2.1.7-SNAPSHOT]
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121) [:2.1.7-SNAPSHOT]
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [:2.1.7-SNAPSHOT]
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) [:2.1.7-SNAPSHOT]
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594) [:2.1.7-SNAPSHOT]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324) [:6.0.0.Final]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.0.0.Final]
更新3:当前的xhtml

更新5

我能够通过使用SelectItem类型的数组列表而不是字符串来修复异常,因此在我的bean中,我有:

createProperties(){
    ArrayList<SelectItem> properties = new ArrayList<SelectItem>();
    properties.add(new SelectItem("roi", "roi"));
    properties.add(new SelectItem("val"."val"));
}
为什么要将命名空间p用于?p通常是primefaces组件,我不确定混合组件库是否是好的实践。试试jsf的标准 请注意,使用列表作为值时,应使用selectItems而不是selectItem

更新 试一试

为什么要将命名空间p用于?p通常是primefaces组件,我不确定混合组件库是否是好的实践。试试jsf的标准 请注意,使用列表作为值时,应使用selectItems而不是selectItem

更新 试一试


在getter中应该使用selectitem而不是string

public ArrayList<SelectItem> getProperties() {
   return properties;
}
并用selectitems填充您的属性

properties.add(new SelectItem(<the value>, <text to display>));

在getter中应该使用selectitem而不是string

public ArrayList<SelectItem> getProperties() {
   return properties;
}
并用selectitems填充您的属性

properties.add(new SelectItem(<the value>, <text to display>));

这会导致ClasscastException,因为在bean的构造函数中,您正在创建一个String类型的集合,即Arraylist,而JSF使用SelectItem类型的集合,即Arraylist。当使用当前设置时,页面呈现为thows ClasscastException,这很明显

可能的修复: 1更改构造函数中集合的类型。成功 动态数组 2如其他人所建议的那样,应该是可行的。但如果没有,请尝试以下操作:

 <ice:selectOneMenu value="myProperties">  
   <ice:selectItems value="#{beanInfo.properties}" />
 </ice:selectOneMenu>

这会导致ClasscastException,因为在bean的构造函数中,您正在创建一个String类型的集合,即Arraylist,而JSF使用SelectItem类型的集合,即Arraylist。当使用当前设置时,页面呈现为thows ClasscastException,这很明显

可能的修复: 1更改构造函数中集合的类型。成功 动态数组 2如其他人所建议的那样,应该是可行的。但如果没有,请尝试以下操作:

 <ice:selectOneMenu value="myProperties">  
   <ice:selectItems value="#{beanInfo.properties}" />
 </ice:selectOneMenu>


您是否尝试了selectItems,而不是selectItem?为什么使用var作为属性?我使用它是因为jsf或icefaces需要获取selectItem对象的集合。您可以按照@roel的建议在value属性中传递它们的集合,也可以传递普通java对象的集合,并使用var、itemValue、itemLabel通过jsf创建这些SelectItems。因此您也可以使用properties或test代替var的属性,对吗,我不确定为什么我获取的java.util.ArrayList无法转换为javaax.faces.model.SelectItem,您过去遇到过这个问题吗?您是否尝试过selectItems,而不是SelectItem?为什么使用var作为属性?我使用它是因为jsf或icefaces需要获取SelectItem对象的集合。您可以按照@roel的建议在value属性中传递它们的集合,也可以传递普通java对象的集合,并使用var、itemValue、itemLabel通过jsf创建这些SelectItems。因此您也可以使用properties或test代替var的属性,对吗,我不确定为什么我获取的java.util.ArrayList不能转换为javaax.faces.model.SelectItem,您过去遇到过这个问题吗?您能展示一下当前的xhtml吗?什么是p:selectItems?它真的是JSF标准的selectItems吗?你能展示p名称空间的声明吗?@NikitaBeloglazov:更新了名称空间的问题declaration@NikitaBeloglazov:这真是太棒了,不是吗?好的。你能说出你的icefaces lib版本吗您能展示当前的xhtml吗?什么是p:selectItems?它真的是JSF标准的selectItems吗?你能展示p名称空间的声明吗?@NikitaBeloglazov:更新了名称空间的问题declaration@NikitaBeloglazov:这真是太棒了,不是吗?好的。你能说出你的icefaces lib版本吗您应该使用并同时将名称空间更改为标准使用f和p xmlns:f=。然后,这就变成了不起作用,抛出了Update2中提到的classcastexception。您还更改为arraylist?您应该使用,同时将名称空间更改为标准使用的f和p xmlns:f=。然后它变成了这不起作用,抛出了Update2中提到的classcastexception你也改成了arraylist?这里引用的myProperties是什么?还有,默认情况下JSF使用arraylist类型的集合?@Rachel:myProperties只是一个文本,它将作为标签出现在你的下拉列表中。我不需要下拉列表,我需要有一个列表框,其中列出了从中返回的arraylist的所有元素managedbean@Rachel:要使用listBox,只需更改componect名称。因此,在XHTML中,您将使用类似这样的内容来代替MyProperty
这里引用的是什么?默认情况下JSF使用的是ArrayList类型的集合吗?@Rachel:myProperties只是一个文本,它将作为标签出现在您的下拉列表中。我不需要下拉列表,我需要有一个列表框,其中列出了从中返回的arraylist的所有元素managedbean@Rachel:要使用listBox,只需更改componect名称。因此,在XHTML中,您将使用类似这样的内容来代替
properties.add(new SelectItem(<the value>, <text to display>));
 <ice:selectOneMenu value="myProperties">  
   <ice:selectItems value="#{beanInfo.properties}" />
 </ice:selectOneMenu>