I'm trying to put one Facelet tag inside forEach loop on .xhtml page, and I keep getting ClassCastException (details attached below). I'm using JSF 2.2.2 and primefaces 4.0 with Tomcat, and my code looks something like this:
<c:forEach items="#{bean.comps}" var="comp">
<c:if test="#{comp.name == 'text'}">
<a:inputText value="#{comp.Value}" />
</c:if>
</c:forEach>
relevant backing bean code
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 is some way standard tag in a project, which consists of label, input component and message field.
I also tried ui:repeat loop, but there is no difference and result is the same. I even tried to transform Facelet tag into composite component, but same exception appears. Does anyone know what seems to be the problem with this?
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)
Thank you all,
<ui:repeat>
instead ? Do you really need to use<c:forEach>
? If yes maybe you should look at these bug issues if they apply to the version you're using (java.net/jira/browse/JAVASERVERFACES-2892 and java.net/jira/browse/JAVASERVERFACES-2937) – Ramic:forEach
withui:repeat
and remove thec:if
then add the#{comp.name == 'text'}
to arendered
attribute in the<a:inputText>
– Ramibean
class code ? and which version of JSF are you using ? – Rami