我正在使用Mojarra 2.2.8和Primefaces 5.2。我需要在ajax请求中包含不同的facelets,所以我在托管bean中使用此代码:
FaceletContext faceletContext = (FaceletContext) context.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY);
if (type.equals("default")) {
faceletContext.includeFacelet(this, "/defaultDlg.xhtml");
}
在 defaultDlg.xhtml 中我有Primefaces动态tabView:
<p:tabView id="contentTabView" onTabShow="PF('contentDlg').initPosition();" dynamic="true">
<p:ajax event="tabChange" listener="#{folderView.onTabChange}"/>
<p:tab title="#{msg['title.documentCard']}">
<p:panel>
<!-- some widgets here... -->
</p:panel>
</p:tab>
<p:tab title="#{msg['title.performance']}">
<!-- DataTable with subTable ... -->
<p:dataTable value="#{folderView.performance}"
id="historyTable" widgetVar="historyTable" var="wf">
<p:columnGroup type="header">
<p:row>
<p:column headerText="#{msg['audit.performance.sendbydesc']}" />
<p:column headerText="#{msg['audit.performance.performerdesc']}" />
</p:row>
</p:columnGroup>
<p:subTable var="task" value="#{wf[5]}">
<f:facet name="header">
<h:outputText value="#{wf[2]}" />
</f:facet>
<p:column>
<h:outputText value="#{task[2]}" />
</p:column>
<p:column>
<h:outputText value="#{task[4]}" />
</p:column>
</p:subTable>
</p:dataTable>
</p:tab>
<!-- more tabs ... -->
我看了this answer on related question,其中用户说&#34;使用FaceletContext是错误的方法,因为稍后它会导致重复的ID和状态管理问题&#34; 没有任何解释。在我的示例中,此方法正确地包含来自 defaultDlg.xhtml 的UIComponents以查看root并在页面上呈现它们。
但是当我点击带有subTable的第二个标签或发出任何ajax请求时,我收到此错误:
严重:java.lang.NumberFormatException:尝试从clientId&n; ntikDoc中提取rowIndex:contentTabView:historyTable:j_id492561291_69346d22:j_id492561291_69346d58&#39;对于输入字符串:&#34; j_id492561291_69346d22&#34; 在javax.faces.component.UIData.invokeOnComponent(UIData.java:1021) at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:1503) at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:713) at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:1503) at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:713) at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:1503) at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:713) 在org.primefaces.component.api.UITabPanel.invokeOnComponent(UITabPanel.java:798) at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:1503) at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:713) at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:1503) at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:713) at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:1503) at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:713) at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:1503) at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:713) at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:1503) at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:713) at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:1503) at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:713) at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:1503) at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:713) at com.sun.faces.application.view.FaceletViewHandlingStrategy.locateComponentByClientId(FaceletViewHandlingStrategy.java:2063) at com.sun.faces.application.view.FaceletViewHandlingStrategy.reapplyDynamicAdd(FaceletViewHandlingStrategy.java:2127) 在com.sun.faces.application.view.FaceletViewHandlingStrategy.reapplyDynamicActions(FaceletViewHandlingStrategy.java:2114) 在com.sun.faces.application.view.FaceletViewHandlingStrategy.buildView(FaceletViewHandlingStrategy.java:961) at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:99) 在com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) 在com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219) 在javax.faces.webapp.FacesServlet.service(FacesServlet.java:647) at sun.reflect.GeneratedMethodAccessor167.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) 在org.apache.catalina.security.SecurityUtil $ 1.run(SecurityUtil.java:323) 在org.apache.catalina.security.SecurityUtil $ 1.run(SecurityUtil.java:321) at java.security.AccessController.doPrivileged(Native Method) 在javax.security.auth.Subject.doAsPrivileged(Subject.java:536) 在org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:356) 在org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:212) 在org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1543) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343) 在org.apache.catalina.core.ApplicationFilterChain.access $ 000(ApplicationFilterChain.java:88) 在org.apache.catalina.core.ApplicationFilterChain $ 1.run(ApplicationFilterChain.java:200) 在org.apache.catalina.core.ApplicationFilterChain $ 1.run(ApplicationFilterChain.java:197) at java.security.AccessController.doPrivileged(Native Method) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:196) 在org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:100) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) 在org.apache.catalina.core.ApplicationFilterChain.access $ 000(ApplicationFilterChain.java:88) 在org.apache.catalina.core.ApplicationFilterChain $ 1.run(ApplicationFilterChain.java:200) 在org.apache.catalina.core.ApplicationFilterChain $ 1.run(ApplicationFilterChain.java:197) at java.security.AccessController.doPrivileged(Native Method) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:196) 在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279) 在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) 在org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655) 在org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595) 在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161) 在org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331) 在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231) at com.sun.enterprise.v3.services.impl.ContainerMapper $ AdapterCallable.call(ContainerMapper.java:317) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195) 在com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860) at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757) 在com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056) 在com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229) at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137) 在com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104) 在com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90) 在com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79) at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54) 在com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59) 在com.sun.grizzly.ContextTask.run(ContextTask.java:71) at com.sun.grizzly.util.AbstractThreadPool $ Worker.doWork(AbstractThreadPool.java:532) 在com.sun.grizzly.util.AbstractThreadPool $ Worker.run(AbstractThreadPool.java:513) 在java.lang.Thread.run(Thread.java:745)
我认为在ajax请求期间可能存在状态保存问题,因为如果我从第二个选项卡中删除subTable,我会在每个ajax请求上收到此警告:
警告:无法使用clientId&#39; ntikDoc保存动态操作:j_id69584408_969820d&#39;因为无法找到UIComponent 警告:无法使用clientId&nbsp; ntikDoc保存动态操作:j_id69584408_969820d_1&#39;因为无法找到UIComponent 警告:无法使用clientId&nbsp; ntikDoc保存动态操作:idtFrom:j_id69584408_969829e&#39;因为无法找到UIComponent 警告:无法使用clientId&nbsp; ntikDoc保存动态操作:idtFrom:j_id69584408_96982b4&#39;因为无法找到UIComponent 警告:无法使用clientId&nbsp; ntikDoc保存动态操作:j_id69584408_96983ee&#39;因为无法找到UIComponent 警告:无法使用clientId&nbsp; ntikDoc保存动态操作:idtTo:j_id69584408_9698056&#39;因为无法找到UIComponent 警告:无法使用clientId&nbsp; ntikDoc保存动态操作:idtTo:j_id69584408_969806c&#39;因为无法找到UIComponent 警告:无法使用clientId&nbsp; ntikDoc保存动态操作:idtTo:j_id69584408_969800a&#39;因为无法找到UIComponent 警告:无法使用clientId&#39; ntikDoc保存动态操作:contentTabView:j_id492561291_69346015&#39;因为无法找到UIComponent 警告:无法使用clientId&nbsp; ntikDoc保存动态操作:contentTabView:j_id492561291_69346015_1&#39;因为无法找到UIComponent 警告:无法使用clientId&nbsp; ntikDoc保存动态操作:contentTabView:contentTable:j_id492561291_69346b92&#39;因为无法找到UIComponent 警告:无法使用clientId&nbsp; ntikDoc保存动态操作:contentTabView:contentTable:j_id492561291_69346bfc&#39;因为无法找到UIComponent 警告:无法使用clientId&nbsp; ntikDoc保存动态操作:contentTabView:perTable:j_id492561291_69346cc4&#39;因为无法找到UIComponent 警告:无法使用clientId&nbsp; ntikDoc保存动态操作:contentTabView:perTable:j_id492561291_69346c26&#39;因为无法找到UIComponent 警告:无法使用clientId&nbsp; ntikDoc保存动态操作:contentTabView:perTable:j_id492561291_69346c10&#39;因为无法找到UIComponent 警告:无法使用clientId&nbsp; ntikDoc保存动态操作:contentTabView:historyTable:j_id492561291_69346d22:j_id492561291_69346d6e&#39;因为无法找到UIComponent 警告:无法使用clientId&nbsp; ntikDoc保存动态操作:contentTabView:historyDocTable:j_id492561291_69346ef9&#39;因为无法找到UIComponent
那么如何正确使用faceletContext.includeFacelet
?