【发布时间】:2012-04-01 03:51:50
【问题描述】:
我的页面上有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>
我的托管 bean 看起来像:
public ArrayList<String> getProperties()
{
return properties;
}
并在构造函数中填充properties,如图所示:
public BeanInfo(){
createProperties();
}
createProperties(){
ArrayList<String> properties = new ArrayList<String>();
properties.add("roi");
properties.add("val");
}
我是 jsf 和 icefaces 的新手,所以不确定这里有什么问题。有什么建议吗?
更新
所以我的表中没有任何内容,但我得到java.util.ArrayList cannot be cast to javaax.faces.model.SelectItem 异常。
更新 2
这是我在Nikita's Approach 之后遇到的例外情况,并将我的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
<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:selectItems value="#{bookBeanInfo.properties}"
var="property"
itemValue="#{property}"
itemLabel="#{property}"/>
</ice:selectManyListbox>
</ice:panelGrid>
<ice:panelGrid>
<ice:outputText value="Name:" style="text-align:left;font-size:20px;" id="bookName"></ice:outputText>
</ice:panelGrid>
<ice:panelGrid>
<ice:inputText id="NameInputText" style="width: 195px;" value="#{bookBeanInfo.bookName}"></ice:inputText>
</ice:panelGrid>
更新 4:命名空间声明
html xmlns="http://www.w3.org/1999/xhtml"
xmlns:icecore="http://www.icefaces.org/icefaces/core"
xmlns:ice="http://www.icesoft.com/icefaces/component"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:ace="http://www.icefaces.org/icefaces/components"
xmlns:p="http://java.sun.com/jsf/core"
xmlns:ice-cc="http://www.icesoft.com/icefaces-composite-comps">
更新5
我能够通过使用 SelectItem 类型的数组列表而不是 String 来修复异常,所以在我的 bean 中,我有:
createProperties(){
ArrayList<SelectItem> properties = new ArrayList<SelectItem>();
properties.add(new SelectItem("roi", "roi"));
properties.add(new SelectItem("val"."val"));
}
在我的xhtml 页面中,我必须使用selectItems 而不是selectItem,因为在我的xhtml 页面上期待收集,因此需要使用selectItems 来遍历它们:
<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:selectItems value="#{beanInfo.properties}"/>
</ice:selectManyListbox>
</ice:panelGrid>
</ice:panelGrid>
【问题讨论】:
-
你能告诉你当前的 xhtml 吗?
-
什么是
p:selectItems?真的是JSF标准selectItems吗?你能显示p命名空间的声明吗? -
@NikitaBeloglazov:更新了命名空间声明的问题
-
@NikitaBeloglazov:这真的很奇怪,不是吗?
-
好的。然后你能说你的icefaces lib版本吗? :)