JSF 2 动态用户界面:包括从 2.1.7 到 2.1.9 不工作

Posted

技术标签:

【中文标题】JSF 2 动态用户界面:包括从 2.1.7 到 2.1.9 不工作【英文标题】:JSF 2 dynamic ui:include not working from 2.1.7 to 2.1.9 【发布时间】:2012-10-18 17:49:27 【问题描述】:

我有一个 JSF 2/CDI webapp,它可以动态配置一些特定的管理页面。它使用一个 bean 来决定要包含哪个页面:

<ui:include src="#myBean.myDynamicPath"/>

为了使其正常工作,我已将使用它的页面添加到 javax.faces.FULL_STATE_SAVING_VIEW_IDS 上下文参数中,并且在将 JSF 库从 2.1.7 更新到 2.1 之前,一切正常。 9(和最新的有同样的问题)。

当我尝试在页面上执行某些操作时,我得到一个很长的异常:

Oct 18, 2012 6:14:10 PM com.sun.faces.util.Util checkIdUniqueness
SEVERE: JSF1007: Duplicate component ID tabs:imagesListForm:imagesListDG:j_idt55 found in view.
Oct 18, 2012 6:14:10 PM com.sun.faces.util.Util checkIdUniqueness
SEVERE: +id: j_id1
    type: javax.faces.component.UIViewRoot@4478de9f
        +id: javax_faces_location_HEAD

        ... (all the view tree here) ...

Oct 18, 2012 6:14:10 PM com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException
SEVERE: Error Rendering View[/admin/objects/edit.xhtml]
java.lang.IllegalStateException: Component ID tabs:imagesListForm:imagesListDG:j_idt55 has already been found in the view.
    at com.sun.faces.util.Util.checkIdUniqueness(Util.java:842)
    at com.sun.faces.util.Util.checkIdUniqueness(Util.java:826)
    at com.sun.faces.util.Util.checkIdUniqueness(Util.java:826)
    at com.sun.faces.util.Util.checkIdUniqueness(Util.java:826)
    at com.sun.faces.util.Util.checkIdUniqueness(Util.java:826)
    at com.sun.faces.util.Util.checkIdUniqueness(Util.java:826)
    at com.sun.faces.util.Util.checkIdUniqueness(Util.java:826)
    at com.sun.faces.util.Util.checkIdUniqueness(Util.java:826)
    at com.sun.faces.util.Util.checkIdUniqueness(Util.java:826)
    at com.sun.faces.util.Util.checkIdUniqueness(Util.java:826)
    at com.sun.faces.util.Util.checkIdUniqueness(Util.java:826)
    at com.sun.faces.application.view.FaceletFullStateManagementStrategy.saveView(FaceletFullStateManagementStrategy.java:686)
    at com.sun.faces.application.StateManagerImpl.saveView(StateManagerImpl.java:89)
    at javax.faces.application.StateManager.getViewState(StateManager.java:553)
    at com.sun.faces.context.PartialViewContextImpl.renderState(PartialViewContextImpl.java:417)
    at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:300)
    at javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:183)
    at javax.faces.component.UIViewRoot.encodeChildren(UIViewRoot.java:981)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:409)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:124)
    at com.ocpsoft.pretty.faces.application.PrettyViewHandler.renderView(PrettyViewHandler.java:163)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
    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:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:145)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at uk.co.novaware.core.cdi.scope.ConversationFilter.doFilter(ConversationFilter.java:36)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
    at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:137)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.jboss.solder.servlet.event.ServletEventBridgeFilter.doFilter(ServletEventBridgeFilter.java:74)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.jboss.solder.servlet.exception.CatchExceptionFilter.doFilter(CatchExceptionFilter.java:65)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at uk.co.novaware.core.cdi.scope.ConversationFilter.doFilter(ConversationFilter.java:36)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:680)

ui:include 的工作方式是否发生了变化?有人有什么想法让它再次工作吗?我需要更新 JSF 库。

【问题讨论】:

能否贴出渲染组件“tabs:imagesListForm:imagesListDG:j_idt55”的相关代码? 你好@Ravi,我放哪个代码都没关系,无论如何它都不起作用,在这种情况下,它是一个 p:dataTable 里面的一个 h:form 里面的一个 p:tab 里面的一个 p:tabView但我也尝试过添加简单的组件,结果是一样的...... @Ravi 不,我已经检查过所有的 id 都是唯一的......如果我使用 JSF 2.1.7 它也可以正常工作...... 【参考方案1】:

快速解决方法:尝试说明所有元素的 ID 值。并确保 ID 是唯一的。

您可以检查生成的 html 中生成的 ID,以确定导致问题的标签。

【讨论】:

以上是关于JSF 2 动态用户界面:包括从 2.1.7 到 2.1.9 不工作的主要内容,如果未能解决你的问题,请参考以下文章

使用 JSF 2.2 动态加载表单

JSF 如何从支持 bean 重定向到支持 bean 中动态构建的 URL?

JSF 2.0将动态表单保存到数据库[重复]

JSF:将页面动态包含到primefaces对话框中

如何从jsf / primefaces中的托管bean向页面添加组件[重复]

是否可以在 JSF 中实现组件的动态树?