1 Reply Latest reply on Jan 8, 2008 2:38 PM by Tony Herstell

    ConcurrentModificationException

    Tony Herstell Master

      I have some markup:

       <f:view>
       <a4j:form styleClass="general_form">
      
       <fieldset class="general_form_fieldset">
      
       <legend class="general_form_legend">
       <h:outputText value="#{messages.booking_fieldset_resources}" />
       </legend>
      
       <s:validateAll>
       <div>
       <center>
       <rich:dataTable id="resourceAddedTable" var="eachResource" value="#{bookingResources}">
       <rich:column>
       <f:facet name="header">
       <h:outputText value="#{messages.booking_resource_column_header}" />
       </f:facet>
       <h:outputText value="#{messages[eachResource.inlLabel]}" />
       </rich:column>
       <rich:column>
       <f:facet name="header">
       <h:outputText value="#{messages.booking_action_column_header}" />
       </f:facet>
       <a4j:commandButton styleClass="general_form_button"
       action="#{bookingController.removeResource(eachResource)}"
       value="#{messages.general_button_remove}" type="submit" reRender="resourceAddedTable">
       </a4j:commandButton>
       </rich:column>
       </rich:dataTable>
       </center>
       </div>
      
       <div>
       <rich:messages id="resourceAdditionAttemptMessages" errorClass="error" warnClass="warn"
       infoClass="info" for="resourceAddedTable" />
       </div>
      
       <div>
       <br />
       </div>
      
       <div>
       <a4j:commandButton id="addResidentTrainer" value="#{messages.resource_resident_trainer}"
       action="#{bookingController.addResource('resource_resident_trainer')}"
       reRender="resourceAddedTable, resourceAdditionAttemptMessages" />
      


      The table is simple updated by the back end when you click add.

      When you click remove its supposed to remove the item from the list.

      However.. I get
      Caused by: java.util.ConcurrentModificationException
       at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372)
       at java.util.AbstractList$Itr.next(AbstractList.java:343)
      


       @DataModel
       private List<ResourceKind> bookingResources;
      
      ...
      
       /* (non-Javadoc)
       * @see nz.co.selwynequestriancentre.action.booking.BookingController#addResource(java.lang.String)
       */
       public String addResource(String resource) {
       log.info(">addResource " + resource);
       ResourceKind resourceKind = resourceHelper.getResourceKind(resource);
       boolean isAlreadyAdded = false;
       for (ResourceKind eachExistingResourceKind : bookingResources) {
       if (resourceKind.getInlLabel().equalsIgnoreCase(eachExistingResourceKind.getInlLabel())) {
       facesMessages.addToControlFromResourceBundle("resourceAdditionAttemptMessages", FacesMessage.SEVERITY_ERROR, "booking_resource_already_added");
       isAlreadyAdded = true;
       }
       }
       if (!isAlreadyAdded) {
       bookingResources.add(resourceKind);
       }
       log.info("<addResource");
       return null;
       }
      
       /* (non-Javadoc)
       * @see nz.co.selwynequestriancentre.action.booking.BookingController#removeResource(nz.co.selwynequestriancentre.model.entity.Resource.ResourceKind)
       */
       public String removeResource(ResourceKind resourceKind) {
       for (ResourceKind eachExistingResourceKind : bookingResources) {
       if (resourceKind.getInlLabel().equalsIgnoreCase(eachExistingResourceKind.getInlLabel())) {
       bookingResources.remove(resourceKind);
       }
       }
       return null;
       }
      ...
      


      Any ideas?

        • 1. Re: ConcurrentModificationException
          Tony Herstell Master

          OOps... Solved.
          Pure Java problem.

          
           /* (non-Javadoc)
           * @see nz.co.selwynequestriancentre.action.booking.BookingController#removeResource(nz.co.selwynequestriancentre.model.entity.Resource.ResourceKind)
           */
           public String removeResource(ResourceKind resourceKind) {
           bookingResources.remove(resourceKind);
          // for (ResourceKind eachExistingResourceKind : bookingResources) {
          // if (resourceKind.getInlLabel().equalsIgnoreCase(eachExistingResourceKind.getInlLabel())) {
          // log.info("found it");
          // bookingResources.r
          // }
          // }
           return null;
           }