0
votes

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,

1
You're looping on a list but not using the selected item, why? (please attach your backing bean code) ... You can't use <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)Rami
Hey Rami, thanks for your time. I changed code sample with more details. I also tried with ui:repeat loop, but result is the same. I will look at your links and will get back soon.milanmilyu
you can try replacing the c:forEach with ui:repeat and remove the c:if then add the #{comp.name == 'text'} to a rendered attribute in the <a:inputText>Rami
and please post your bean class code ? and which version of JSF are you using ?Rami

1 Answers

0
votes

I managed to get it to work. Following Rami's links, I found out that mentioned bug was fixed in 2.2.3 version, so now everything works as planned. Thanks again.