我正面临使用java.lang.IndexOutOfBoundsException
TabView 和 TreeTable 组合保存视图状态的过程。我有一个 TreeNodes 列表,并为它们中的每一个创建一个 TreeTable。每个 p:treeTable 都在一个复合组件内,该组件又包含在 ap:tab 中。树表的某些列具有 p:input 元素,我正在使用 p:ajax 处理值并使用“p:ajax”的 primefaces“update”属性更新一些 dom 对象。对于索引 > 0 的树节点的树表,当针对索引大于第一个树节点(索引 = 0)大小的任何行触发 ajax 时,我收到以下错误:
java.lang.IndexOutOfBoundsException: Index: 19, Size: 4
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.get(ArrayList.java:322)
at org.primefaces.component.api.UITree.findTreeNode(UITree.java:121)
at org.primefaces.component.api.UITree.setRowKey(UITree.java:80)
at org.primefaces.component.api.UITree.visitTree(UITree.java:417)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UINamingContainer.visitTree(UINamingContainer.java:163)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIForm.visitTree(UIForm.java:362)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at org.primefaces.component.api.UIData.visitRows(UIData.java:748)
at org.primefaces.component.api.UIData.visitTree(UIData.java:654)
at org.primefaces.component.tabview.TabView.visitTree(TabView.java:433)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UINamingContainer.visitTree(UINamingContainer.java:163)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at org.primefaces.component.accordionpanel.AccordionPanel.visitTree(AccordionPanel.java:395)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UINamingContainer.visitTree(UINamingContainer.java:163)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at com.sun.faces.application.view.FaceletPartialStateManagementStrategy.saveView(FaceletPartialStateManagementStrategy.java:473)
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:418)
at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:301)
at javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:183)
at javax.faces.component.UIViewRoot.encodeChildren(UIViewRoot.java:982)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:411)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:124)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
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:304)
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 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
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:662)
Aug 21, 2013 11:43:44 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [Faces Servlet] in context with path [/igamt-ui] threw exception
java.lang.IllegalStateException: CDATA tags may not nest
at com.sun.faces.renderkit.html_basic.HtmlResponseWriter.startCDATA(HtmlResponseWriter.java:664)
at javax.faces.context.ResponseWriterWrapper.startCDATA(ResponseWriterWrapper.java:172)
at javax.faces.context.PartialResponseWriter.startError(PartialResponseWriter.java:342)
at org.primefaces.context.PrimePartialResponseWriter.startError(PrimePartialResponseWriter.java:155)
at com.sun.faces.context.AjaxExceptionHandlerImpl.handlePartialResponseError(AjaxExceptionHandlerImpl.java:200)
at com.sun.faces.context.AjaxExceptionHandlerImpl.handle(AjaxExceptionHandlerImpl.java:124)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:119)
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:304)
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 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
似乎 p:ajax 总是引用第一个树节点(索引 = 0),其大小(子节点数)为 4。
Here is my composite component: treeTableComponent.xhtml
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:myComponents="http://java.sun.com/jsf/composite/myComponents">
<composite:interface>
<composite:attribute name="managerBean" required="true" />
<composite:attribute name="node" required="true" />
</composite:interface>
<composite:implementation>
<div id="#{cc.id}">
<ui:param name="currentNode" value="#{cc.attrs.node}" />
<p:treeTable resizableColumns="true" value="#{currentNode}"
id="segmentmaker_segment_tree" var="nodeData"
scrollable="true">
<p:ajax event="collapse" global="true"
listener="#{cc.attrs.managerBean.onNodeCollapse}" process="@this" />
<p:ajax event="expand" global="true"
listener="#{cc.attrs.managerBean.onNodeExpand}" process="@this" />
<p:column style="width:100px"
headerText="Column A">
<p:outputPanel layout="block">
<p:outputPanel id="column_a">
<p:inputText
value="#{nodeData.a}" size="5"
required="false">
<p:ajax event="blur" partialSubmit="true"
update="column_a column_b"
global="true" async="true"
listener="#{cc.attrs.managerBean.process}">
</p:ajax>
</p:inputText>
</p:outputPanel>
</p:outputPanel>
</p:column>
<p:column style="width:100px"
headerText="Column B">
<p:outputPanel id="column_b">
<p:inputText
value="#{nodeData.b}" size="5"
required="false">
<p:ajax event="blur" partialSubmit="true"
update="column_a column_b"
global="true" async="true"
listener="#{cc.attrs.managerBean.process}">
</p:ajax>
</p:inputText>
</p:outputPanel>
</p:outputPanel>
</p:column>
</p:treeTable>
</div>
</composite:implementation>
</ui:composition>
这是我的支持 bean:ManagerBean.java
public class ManagerBean implements Serializable {
public ManagerBean(){
nodes = new ArrayList<TreeNode>();
nodes.add(new DefaultTreeNode("one", new DataModel("one"), null));
nodes.add(new DefaultTreeNode("two", new DataModel("two"), null));
nodes.add(new DefaultTreeNode("three", new DataModel("three"), null));
nodes.add(new DefaultTreeNode("four", new DataModel("four"), null));
//add childrens
for(int i = 0; i < nodes.size(); i++){
for(int j = 0; j < 10; i++){
new DefaultTreeNode("one"+(j+1), new DataModel("one"+(j+1)), nodes.get(i);
}
}
}
private List<TreeNode> nodes = null;
public void process(AjaxBehaviorEvent event) {
try {
FacesContext context = FacesContext.getCurrentInstance();
DataModel currentSegmentChildModel =
context.getApplication().evaluateExpressionGet(context, "#{nodeData}",
DataModel.class);
TreeNode node =
context.getApplication().evaluateExpressionGet(context, "#{currentNode}",
EditorTreeNode.class);
//business logic
} catch (ValidationException e) {}
}
public void onNodeExpand(NodeExpandEvent event) {
event.getTreeNode().setExpanded(true);
}
public void onNodeCollapse(NodeCollapseEvent event) {
event.getTreeNode().setExpanded(false);
}
}
这里是客户端调用 treeTableComponent 复合组件。客户端本身就是一个复合组件:treeTableComponents.xhtml
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:myComponents="http://java.sun.com/jsf/composite/myComponents">
<composite:interface>
<composite:attribute name="managerBean" required="true" />
</composite:interface>
<composite:implementation>
<div id="#{cc.id}">
<p:tabView
cache="true" dynamic="true" var="myNode"
value="#{cc.attrs.managerBean.nodes}">
<p:tab header="#{myNode.name}">
<h:form prependId="false">
<p:outputPanel layout="block">
<myComponents:treeTableComponent
node="#{myNode}"
managerBean="#{cc.attrs.managerBean}" />
</p:outputPanel>
</h:form>
</p:tab>
</p:tabView>
</div>
</composite:implementation>
</ui:composition>
这是数据模型代码:DataModel.java
public class DataModel implements Serializable {
private String a;
private String b;
public String getA(){
return a;
}
public String getB(){
return b;
}
public void setA(String a){
this.a = a;
}
public void setB(String b){
this.b = b;
}
}
我正在使用 PrimeFaces 3.5 和 Mojarra 2.1.17。