2 Replies Latest reply on Aug 13, 2010 1:51 PM by Leo van den berg

    problems with objects synchronization

    Lelo Pieri Newbie

      Hi,


      I have one object(A) that has a list of objects(B), for each element of 2nd list there are one list of objects(C) and for each c element there are one single object(D).


      Abstracting the way how it is showed on the view, what I whant is remove de D element.


      The relevant code is follow



      <s:div id="divDevices">
           <rich:dataGrid styleClass="center" value="#{_producerProvider.deviceProducerProviders}" var="_deviceProducerProvider" columns="5" style="margin-top:10px;">
           <h:panelGrid columns="2">
                <a4j:commandLink action="#{companyHome.removeDeviceFromDeviceProvider(_deviceProducerProvider)}" 
                     reRender="divDevices"
                     rendered="#{empty _deviceProducerProvider.fileApplications}">
                     <h:graphicImage value="/resources/img/cancel-12x12.png"/>
                </a4j:commandLink>
           <h:graphicImage value="/resources/img/add.png" rendered="#{not empty _deviceProducerProvider.fileApplications}"/>
           <h:outputLabel value="#{_deviceProducerProvider.device.serialNumber}"/>
           </h:panelGrid>
           </rich:dataGrid>
      </s:div>





      @Name("companyHome")
      public class CompanyHome extends EntityHomeValidation<Company> {
      ...
           public void removeDeviceFromDeviceProvider(DeviceProducerProvider deviceProducerProvider){
                entityManager.remove(deviceProducerProvider);
                entityManager.flush();
      //          log.debug("deviceProducerProvider: " + deviceProducerProvider);
      //          int index = getInstance().getProviders().indexOf(deviceProducerProvider.getProducerProvider());
      //          log.debug("Index: " + index);
      //          ProducerProvider producerProvider = getInstance().getProviders().get(index);
      //          producerProvider.getDeviceProducerProviders().remove(deviceProducerProvider);
      //          new GenericDAO().update(producerProvider);
      //          this.update();
           } 
      ...
      }



      I'm having two situations for method removeDeviceFromDeviceProvider:
      1st: the non commented code remove the object just from the DB but not from the managed object.


      2nd: the commented code do the oposite. Remove from the managed object but not from DB.


      I think I should not do the both things or I will not be using the resources of the framework and will start having synchronizing problems.


      Does anybody have any idea what should I do?


      Thanks for all and sorry for my bad english.