I am using Mojarra 2.2.8 and Primefaces 5.2. I need to include different facelets on ajax request, so i use this code in managed bean:
FaceletContext faceletContext = (FaceletContext) context.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY);
if (type.equals("default")) {
faceletContext.includeFacelet(this, "/defaultDlg.xhtml");
}
In defaultDlg.xhtml i have Primefaces dynamic 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 ... -->
I looked this answer on related question where user says that "Use FaceletContext is the wrong way to do it, because later it causes duplicate id and state management issues" without any explanation. In my example this method correctly includes UIComponents from defaultDlg.xhtml to view root and renders them on page.
But when i click on second tab with subTable or make any ajax request i get this error:
Severe: java.lang.NumberFormatException: Trying to extract rowIndex from clientId 'ntikDoc:contentTabView:historyTable:j_id492561291_69346d22:j_id492561291_69346d58' For input string: "j_id492561291_69346d22" at 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) at 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) at com.sun.faces.application.view.FaceletViewHandlingStrategy.reapplyDynamicActions(FaceletViewHandlingStrategy.java:2114) at com.sun.faces.application.view.FaceletViewHandlingStrategy.buildView(FaceletViewHandlingStrategy.java:961) at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:99) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219) at 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) at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:323) at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:321) at java.security.AccessController.doPrivileged(Native Method) at javax.security.auth.Subject.doAsPrivileged(Subject.java:536) at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:356) at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:212) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1543) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343) at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:88) at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:200) at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:197) at java.security.AccessController.doPrivileged(Native Method) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:196) at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:100) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:88) at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:200) at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:197) at java.security.AccessController.doPrivileged(Native Method) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:196) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331) at 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) at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860) at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757) at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056) at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229) at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90) at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79) at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54) at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59) at com.sun.grizzly.ContextTask.run(ContextTask.java:71) at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532) at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513) at java.lang.Thread.run(Thread.java:745)
I thik that there might be a problem with state saving during ajax request because if i remove subTable from second tab i get this warnings on every ajax request:
Warning: Unable to save dynamic action with clientId 'ntikDoc:j_id69584408_969820d' because the UIComponent cannot be found Warning: Unable to save dynamic action with clientId 'ntikDoc:j_id69584408_969820d_1' because the UIComponent cannot be found Warning: Unable to save dynamic action with clientId 'ntikDoc:idtFrom:j_id69584408_969829e' because the UIComponent cannot be found Warning: Unable to save dynamic action with clientId 'ntikDoc:idtFrom:j_id69584408_96982b4' because the UIComponent cannot be found Warning: Unable to save dynamic action with clientId 'ntikDoc:j_id69584408_96983ee' because the UIComponent cannot be found Warning: Unable to save dynamic action with clientId 'ntikDoc:idtTo:j_id69584408_9698056' because the UIComponent cannot be found Warning: Unable to save dynamic action with clientId 'ntikDoc:idtTo:j_id69584408_969806c' because the UIComponent cannot be found Warning: Unable to save dynamic action with clientId 'ntikDoc:idtTo:j_id69584408_969800a' because the UIComponent cannot be found Warning: Unable to save dynamic action with clientId 'ntikDoc:contentTabView:j_id492561291_69346015' because the UIComponent cannot be found Warning: Unable to save dynamic action with clientId 'ntikDoc:contentTabView:j_id492561291_69346015_1' because the UIComponent cannot be found Warning: Unable to save dynamic action with clientId 'ntikDoc:contentTabView:contentTable:j_id492561291_69346b92' because the UIComponent cannot be found Warning: Unable to save dynamic action with clientId 'ntikDoc:contentTabView:contentTable:j_id492561291_69346bfc' because the UIComponent cannot be found Warning: Unable to save dynamic action with clientId 'ntikDoc:contentTabView:perTable:j_id492561291_69346cc4' because the UIComponent cannot be found Warning: Unable to save dynamic action with clientId 'ntikDoc:contentTabView:perTable:j_id492561291_69346c26' because the UIComponent cannot be found Warning: Unable to save dynamic action with clientId 'ntikDoc:contentTabView:perTable:j_id492561291_69346c10' because the UIComponent cannot be found Warning: Unable to save dynamic action with clientId 'ntikDoc:contentTabView:historyTable:j_id492561291_69346d22:j_id492561291_69346d6e' because the UIComponent cannot be found Warning: Unable to save dynamic action with clientId 'ntikDoc:contentTabView:historyDocTable:j_id492561291_69346ef9' because the UIComponent cannot be found
So how to use faceletContext.includeFacelet
correctly?