我试图在.xhtml页面上的forEach循环内放置一个Facelet标记,并且我不断获得ClassCastException(详细信息附在下面)。我使用JSF 2.2.2和带Tomcat的primefaces 4.0,我的代码看起来像这样:
<c:forEach items="#{bean.comps}" var="comp">
<c:if test="#{comp.name == 'text'}">
<a:inputText value="#{comp.Value}" />
</c:if>
</c:forEach>
相关后台bean代码
private List<UIComponent> comps = new ArrayList<UIComponent>();
public List<UIComponent> getComps() {
return comps;
}
public void setComps(List<UIComponent> comps) {
this.comps = comps;
}
@PostConstruct
public void init(){
. . . . .
UIComponent comp = new UIComponent();
comp.setName("text");
comp.setValue(val);
comps.add(comp);
. . . . .
}
InputText Facelet是项目中的标准标签,它由标签、输入组件和消息字段组成。
我也尝试了ui:repeat循环,但没有区别,结果是相同的。我甚至尝试将Facelet标记转换为复合组件,但出现了同样的异常。有人知道这有什么问题吗?
java.lang.ClassCastException: com.sun.faces.facelets.tag.jstl.core.ForEachHandler$ForEachFaceletContext cannot be cast to com.sun.faces.facelets.FaceletContextImplBase
at com.sun.faces.facelets.tag.UserTagHandler.apply(UserTagHandler.java:126)
at com.sun.faces.facelets.tag.jstl.core.ForEachHandler.apply(ForEachHandler.java:230)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:95)
at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:190)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
at com.sun.faces.facelets.tag.ui.DefineHandler.applyDefinition(DefineHandler.java:106)
at com.sun.faces.facelets.tag.ui.DecorateHandler.apply(DecorateHandler.java:164)
at com.sun.faces.facelets.impl.DefaultFaceletContext$TemplateManager.apply(DefaultFaceletContext.java:395)
at com.sun.faces.facelets.impl.DefaultFaceletContext.includeDefinition(DefaultFaceletContext.java:366)
at com.sun.faces.facelets.tag.ui.InsertHandler.apply(InsertHandler.java:111)
谢谢大家,
我设法使它工作。根据Rami的链接,我发现提到的bug在2.2.3版本中被修复了,所以现在一切都按计划进行。再次感谢。