ConcurrentModificationException

ConcurrentModificationException

我有一个<h:column><h:selectBooleanCheckbox>的数据表。该<h:column>的方面标头和DataTable行内容均为<h:selectBooleanCheckbox>。下面是我使用的代码:

<h:form>
    <h:dataTable
        value="#{employeeService.employeeList }"
        var="empl"
        binding="#{employeeService.dataTablebinding }">
        ......
        ......
        ......
        <h:column>
            <f:facet name="header">
                <h:selectBooleanCheckbox id="chkBoxAll" value="#{empl.checked }" valueChangeListener="#{employeeService.checkAll }" onclick="submit()"></h:selectBooleanCheckbox>
            </f:facet>
            <h:selectBooleanCheckbox id="tableChkBox" value="#{empl.checked }" valueChangeListener="#{employeeService.getCheckChanged }" onclick="submit()"></h:selectBooleanCheckbox>
        </h:column>
    </h:dataTable>
</h:form>


当我单击构面标头复选框时,我希望所有行复选框都被选中,未选中的复选框也一样。这是该方面标头复选框的ValueChangeListener的代码:

public void checkAll(ValueChangeEvent event){
    for(Employee empl : employeeList){
        employeeList.remove(empl);
        empl.setChecked(true);
        employeeList.add(empl);
    }
}


我得到以下看法:

SEVERE: AbortProcessingException thrown when processing event of type 'javax.faces.component.WrapperEvent' during phase 'PROCESS_VALIDATIONS 3' for component with ID or Client ID of 'j_id7'
        27 Apr, 2013 8:20:38 PM javax.faces.component.UIViewRoot broadcastEvents
        SEVERE: javax.faces.event.AbortProcessingException: java.util.ConcurrentModificationException
        javax.faces.event.AbortProcessingException: java.util.ConcurrentModificationException
            at javax.faces.event.MethodExpressionValueChangeListener.processValueChange(MethodExpressionValueChangeListener.java:93)
            at javax.faces.event.ValueChangeEvent.processListener(ValueChangeEvent.java:134)
            at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:771)
            at javax.faces.component.UIData.broadcast(UIData.java:943)
            at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:444)
            at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:701)
            at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
            at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
            at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
            at com.icesoft.faces.webapp.http.core.JsfLifecycleExecutor.apply(JsfLifecycleExecutor.java:18)
            at com.icesoft.faces.webapp.http.core.ReceiveSendUpdates.renderCycle(ReceiveSendUpdates.java:132)
            at com.icesoft.faces.webapp.http.core.ReceiveSendUpdates.service(ReceiveSendUpdates.java:74)
            at com.icesoft.faces.webapp.http.core.RequestVerifier.service(RequestVerifier.java:31)
            at com.icesoft.faces.webapp.http.common.standard.PathDispatcherServer.service(PathDispatcherServer.java:24)
            at com.icesoft.faces.webapp.http.servlet.BasicAdaptingServlet.service(BasicAdaptingServlet.java:16)
            at com.icesoft.faces.webapp.http.servlet.PathDispatcher.service(PathDispatcher.java:23)
            at com.icesoft.faces.webapp.http.servlet.SessionDispatcher.service(SessionDispatcher.java:53)
            at com.icesoft.faces.webapp.http.servlet.SessionVerifier.service(SessionVerifier.java:26)
            at com.icesoft.faces.webapp.http.servlet.PathDispatcher.service(PathDispatcher.java:23)
            at com.icesoft.faces.webapp.http.servlet.MainServlet.service(MainServlet.java:131)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
            at com.icesoft.faces.webapp.xmlhttp.BlockingServlet.service(BlockingServlet.java:56)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
            at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
            at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
            at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291)
            at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
            at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
            at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
            at java.lang.Thread.run(Thread.java:662)
        Caused by: java.util.ConcurrentModificationException
            at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372)
            at java.util.AbstractList$Itr.next(AbstractList.java:343)
            at com.infy.service.DataTableService.checkAll(DataTableService.java:66)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:597)
            at org.apache.el.parser.AstValue.invoke(AstValue.java:191)
            at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
            at javax.faces.event.MethodExpressionValueChangeListener.processValueChange(MethodExpressionValueChangeListener.java:91)
            ... 33 more


请让我知道此ConcurrentModificationException的原因。

最佳答案

for(Employee empl : employeeList){
    empl.setChecked(true);
    }


如Luigi所述,您无需从列表中删除该员工。

关于java - JSF 1.2:java.util.ConcurrentModificationException,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16253581/

10-11 21:37