<t:panelNavigation2> 原因 javax.faces.FacesException: 无法添加相同的组件两次

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

我在 WildFly 8.2.0 上为 JSF 2.0 使用 Tomahawk20 1.1.14。使用 <t:panelNagivation2> 时,抛出以下异常:

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

这是怎么引起的,我该如何解决? 这是堆栈跟踪:

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

将 Wildfly 降级为使用 JSF 2.1.29-04(这是最新的 2.1.x 版本)会引发以下错误:

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

实际上 class

javax.faces.view.ViewScoped

在jsf中缺失-api.jar

用于 JSF 2.0 的战斧与 JSF 2.2 不完全兼容。某些组件可能工作,但其他组件可能不工作。 <t:panelNavigation2>就是这样一个。您遇到的异常是动态组件树操作错误的结果(以前用于解决旧的 JSF 1.x 跟踪编程组件树更改的错误)。

您有 2 个选择:

  1. 降级到 JSF 2.1/2.0。您可以使用与此处回答相同的说明:Upgrade JSF / Mojarra in JBoss AS / EAP / WildFly 您显然只会错过 JSF 2.2 特定功能。

  2. 或者,掉落战斧。 MyFaces 停止了 Tomahawk 的开发(至少,它不再维护多年)。许多 utilities/enhancements 已经在标准 JSF 中被接管。至于视觉组件,寻找另一个 UI 组件库,例如 PrimeFaces,或者直接使用 "plain vanilla" HTML/CSS(如果您不认为支持 IE6/7浏览器,然后菜单相对简单 <ul><li> 和一点 CSS).