jsfjsf-2tomahawk

<t:panelNavigation2> causes javax.faces.FacesException: Cannot add the same component twice


I am using Tomahawk20 1.1.14 for JSF 2.0 on WildFly 8.2.0. When using <t:panelNagivation2>, the below exception is thrown:

javax.faces.FacesException: Cannot add the same component twice

How is this caused and how can I solve it? Here is the stack trace:

Caused by: javax.faces.FacesException: Cannot add the same component twice: nav:panel-nav:nav_panel-nav_uinavmitem1
    at com.sun.faces.context.StateContext$DynamicAddRemoveListener.handleAddRemoveWithAutoPrune(StateContext.java:751) [jsf-impl-2.2.8-jbossorg-1.jar:]
    at com.sun.faces.context.StateContext$DynamicAddRemoveListener.handleAdd(StateContext.java:678) [jsf-impl-2.2.8-jbossorg-1.jar:]
    at com.sun.faces.context.StateContext$AddRemoveListener.processEvent(StateContext.java:352) [jsf-impl-2.2.8-jbossorg-1.jar:]
    at com.sun.faces.context.StateContext$DynamicAddRemoveListener.processEvent(StateContext.java:568) [jsf-impl-2.2.8-jbossorg-1.jar:]
    at javax.faces.event.SystemEvent.processListener(SystemEvent.java:108) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
    at javax.faces.event.ComponentSystemEvent.processListener(ComponentSystemEvent.java:118) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
    at com.sun.faces.application.ApplicationImpl.processListenersAccountingForAdds(ApplicationImpl.java:2239) [jsf-impl-2.2.8-jbossorg-1.jar:]
    at com.sun.faces.application.ApplicationImpl.invokeViewListenersFor(ApplicationImpl.java:2057) [jsf-impl-2.2.8-jbossorg-1.jar:]
    at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:292) [jsf-impl-2.2.8-jbossorg-1.jar:]
    at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:247) [jsf-impl-2.2.8-jbossorg-1.jar:]
    at org.jboss.as.jsf.injection.weld.ForwardingApplication.publishEvent(ForwardingApplication.java:299) [wildfly-jsf-injection-8.2.0.Final.jar:8.2.0.Final]
    at javax.faces.component.UIComponentBase.publishAfterViewEvents(UIComponentBase.java:2253) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
    at javax.faces.component.UIComponentBase.doPostAddProcessing(UIComponentBase.java:1934) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
    at javax.faces.component.UIComponentBase.setParent(UIComponentBase.java:447) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
    at org.apache.myfaces.custom.navmenu.htmlnavmenu.HtmlNavigationMenuRenderer.addUINavigationMenuItems(HtmlNavigationMenuRenderer.java:355) [tomahawk20-1.1.14.jar:1.1.14]
    at org.apache.myfaces.custom.navmenu.htmlnavmenu.HtmlNavigationMenuRenderer.preprocessNavigationItems(HtmlNavigationMenuRenderer.java:340) [tomahawk20-1.1.14.jar:1.1.14]
    at org.apache.myfaces.custom.navmenu.htmlnavmenu.HtmlNavigationMenuRenderer.encodeEnd(HtmlNavigationMenuRenderer.java:175) [tomahawk20-1.1.14.jar:1.1.14]
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
    at javax.faces.render.Renderer.encodeChildren(Renderer.java:176) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:889) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:456) [jsf-impl-2.2.8-jbossorg-1.jar:]
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:133) [jsf-impl-2.2.8-jbossorg-1.jar:]
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
    at org.apache.myfaces.tomahawk.application.ResourceViewHandlerWrapper.renderView(ResourceViewHandlerWrapper.java:169) [tomahawk20-1.1.14.jar:1.1.14]
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120) [jsf-impl-2.2.8-jbossorg-1.jar:]
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.2.8-jbossorg-1.jar:]
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219) [jsf-impl-2.2.8-jbossorg-1.jar:]
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
    ... 20 more

Downgrading the Wildfly to use JSF 2.1.29-04 (which is the latest 2.1.x version) throws the following error:

Caused by: java.lang.ClassNotFoundException: javax.faces.view.ViewScoped from [Module "org.jboss.as.jsf:main" from local module loader @15b3e5b (finder: local module finder @61ca2dfa (roots: /wildfly_8.2.0_final_acd/wildfly_8.2.0_final_acd/modules,/wildfly_8.2.0_final_acd/wildfly_8.2.0_final_acd/modules/system/layers/base))]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:213)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:459)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:408)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:389)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:134)
... 24 more

And in effect the class

javax.faces.view.ViewScoped

is missing in the jsf-api.jar


Solution

  • Tomahawk for JSF 2.0 is not fully compatible with JSF 2.2. Some components may work, but others may not work. The <t:panelNavigation2> is such one. The exception you faced is consequence of a bug in dynamic component tree manipulation (which was previously used to workaround an old JSF 1.x bug in tracking programmatic component tree changes).

    You have 2 options:

    1. Downgrade to JSF 2.1/2.0. You can use the same instructions as answered here: Upgrade JSF / Mojarra in JBoss AS / EAP / WildFly You'll obviously only miss JSF 2.2 specific features.

    2. Or, drop Tomahawk. MyFaces stopped development of Tomahawk (at least, it isn't maintained anymore for years). A lot of utilities/enhancements are already taken over in standard JSF. As to visual components, look for another UI component library such as PrimeFaces, or just use "plain vanilla" HTML/CSS (if you don't consider IE6/7 as supported browsers, then menus are relatively trivial with <ul><li> and a bit of CSS).