javax.faces.FacesException: Cannot add the same component twice in JBoss EAP when dyanmically adding children in PreRenderViewEvent
Issue
- We are dynamically adding some child components to our custom component when the PreRenderViewEvent occurs, and getting the exception
Cannot add the same component twiceexception:
public CustomComponent() {
FacesContext context = FacesContext.getCurrentInstance();
UIViewRoot root = context.getViewRoot();
root.subscribeToViewEvent( PreRenderViewEvent.class, this );
}
@Override
public void processEvent(SystemEvent event) throws AbortProcessingException {
clearMyChildren(this);
addMyChildren(this);
}
@Override
public boolean isListenerForSource(Object source) {
log.info("source: " + source);
return ( source instanceof UIViewRoot );
}
SEVERE [javax.enterprise.resource.webcontainer.jsf.context] (http-127.0.0.1:8080-1) javax.faces.FacesException: Cannot add the same component twice: form:top:example:my-repeat
at com.sun.faces.context.StateContext$DynamicAddRemoveListener.handleAddRemoveWithAutoPrune(StateContext.java:751)
at com.sun.faces.context.StateContext$DynamicAddRemoveListener.handleAdd(StateContext.java:678)
at com.sun.faces.context.StateContext$AddRemoveListener.processEvent(StateContext.java:352)
at com.sun.faces.context.StateContext$DynamicAddRemoveListener.processEvent(StateContext.java:568)
at javax.faces.event.SystemEvent.processListener(SystemEvent.java:106)
at com.sun.faces.application.ApplicationImpl.processListenersAccountingForAdds(ApplicationImpl.java:2215)
at com.sun.faces.application.ApplicationImpl.invokeViewListenersFor(ApplicationImpl.java:2033)
at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:292)
at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:247)
at javax.faces.component.UIComponentBase.publishAfterViewEvents(UIComponentBase.java:2203)
at javax.faces.component.UIComponentBase.publishAfterViewEvents(UIComponentBase.java:2208)
at javax.faces.component.UIComponentBase.publishAfterViewEvents(UIComponentBase.java:2216)
at javax.faces.component.UIComponentBase.publishAfterViewEvents(UIComponentBase.java:2208)
at javax.faces.component.UIComponentBase.publishAfterViewEvents(UIComponentBase.java:2216)
at javax.faces.component.UIComponentBase.publishAfterViewEvents(UIComponentBase.java:2208)
at javax.faces.component.UIComponentBase.doPostAddProcessing(UIComponentBase.java:1885)
at javax.faces.component.UIComponentBase.setParent(UIComponentBase.java:405)
at javax.faces.component.UIComponentBase$ChildrenList.add(UIComponentBase.java:2637)
at javax.faces.component.UIComponentBase$ChildrenList.add(UIComponentBase.java:2609)
at com.sun.faces.facelets.tag.jsf.ComponentSupport.addComponent(ComponentSupport.java:492)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.addComponentToView(ComponentTagHandlerDelegateImpl.java:345)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.addComponentToView(ComponentTagHandlerDelegateImpl.java:328)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:218)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
at com.sun.faces.facelets.tag.composite.ImplementationHandler.apply(ImplementationHandler.java:81)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:95)
at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:87)
at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:320)
at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:379)
at com.sun.faces.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:326)
at org.jboss.examples.jsf.util.Components.includeCompositeComponent(Components.java:258)
at org.jboss.examples.jsf.components.uirepeat.UIRepeatComponent.addMyChildren(UIRepeatComponent.java:93)
at org.jboss.examples.jsf.components.uirepeat.UIRepeatComponent.processEvent(UIRepeatComponent.java:123)
at javax.faces.event.SystemEvent.processListener(SystemEvent.java:106)
at com.sun.faces.application.ApplicationImpl.processListenersAccountingForAdds(ApplicationImpl.java:2215)
at com.sun.faces.application.ApplicationImpl.invokeViewListenersFor(ApplicationImpl.java:2033)
at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:292)
at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:247)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:107)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:231)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149)
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:150)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:854)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:656)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:926)
at java.lang.Thread.run(Thread.java:745)
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 7.x
- 6.x
- JSF 2.1
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
