5 Replies Latest reply on Oct 5, 2006 4:10 PM by dimival

    DataService fill method BUG

    dimival Level 1
      I have an application with two DataService objects, each one associated to different destinations (Java Assemblers) and each one has a different arrayCollection asociated:

      <mx:DataService id="sistemasDS" destination="sistemas" autoCommit="false" autoSyncEnabled="true" autoMerge="true"/>
      <mx:ArrayCollection id="sistemasList"/>

      <mx:DataService id="rolesDS" destination="roles" autoCommit="false" autoSyncEnabled="true" autoMerge="true"/>
      <mx:ArrayCollection id="rolesList"/>

      The first DataService works fine, i can make a call to the dataService.fill( ) method and the ArrayCollection is filled with the
      list obtained from the Java Assembler, i can insert, delete and update items and the ArrayCollection is autorefreshed normally.

      The second one is not working correctly, for this one i have two possibilites for the fill method, one with an extra parameter and one without extra parameters, like this:

      Flex code
      if (some condition) {
      rolesDS.fill(rolesList, sistemaObj);
      }
      else {
      rolesDS.fill(rolesList);
      }

      Java Assembler code
      public Collection fill(List fillParameters) {
      List resultados = new ArrayList();
      if (fillParameters.size() > 0) {
      resultados =
      getServiceData().findRolesBySistemaId(fillParameters.get(0));
      }
      else {
      resultados = getServiceData().findAllRoles();
      }
      return resultados;
      }

      The problem is the following: I call the first fill method (the one with the extra parameter) and the ArrayCollection (rolesList) is filled with the results from the JavaAssembler. Then I insert a new item by calling the dataService.createItem(item) method, this method in the Assembler inserts a new register into the database, then the Assembler re-executes the fill method and returns the new result list BUT the ArrayCollection in flex (rolesList) is not being refreshed.
      The funny thing is that this only happens when i try to insert a new item, if i delete or update an item it works fine, refreshing the ArrayCollection (rolesList)

      Why is this happening? Why it isn't being refreshed like the first DataService?? I am pretty sure that the Java Assembler is calling the fill method after creating an item (i used System.out.println to verify this and if i call the first fill method again on Flex, then the new register appears) but for some reason the ArrayCollection is not being refreshed.

      Any ideas???
        • 1. DataService fill method bug
          T._Ruggles Level 1
          Good morning,

          Would you post your complete destination declaration as well as DS instantiation and settings that you are using?

          Thanks.
          • 2. Re: DataService fill method bug
            dimival Level 1
            Sure:

            Data-management.xml
            <destination id="sistemas">
            <adapter ref="java-dao" />
            <properties>
            <source>com.intercam.seguridad.assembler.SistemasAssembler</source>
            <scope>application</scope>
            <metadata>
            <identity property="sisId"/>
            </metadata>
            <use-transactions>false</use-transactions>
            <auto-sync-enabled>true</auto-sync-enabled>
            </properties>
            </destination>

            <destination id="roles">
            <adapter ref="java-dao" />
            <properties>
            <source>com.intercam.seguridad.assembler.RolesAssembler</source>
            <scope>application</scope>
            <metadata>
            <identity property="rolId"/>
            </metadata>
            <use-transactions>false</use-transactions>
            <auto-sync-enabled>true</auto-sync-enabled>
            </properties>
            </destination>

            DataServices

            <mx:DataService id="sistemasDS" destination="sistemas" autoCommit="false" autoSyncEnabled="true" autoMerge="true"/>
            <mx:ArrayCollection id="sistemasList"/>

            <mx:DataService id="rolesDS" destination="roles" autoCommit="false" autoSyncEnabled="true" autoMerge="true"/>
            <mx:ArrayCollection id="rolesList"/>

            For the rolesDS i have two possible calls of the fill method:

            if (some condition) {
            rolesDS.fill(rolesList, object);
            }
            else {
            rolesDS.fill(rolesList);
            }

            If i use the second fill (without extra-parameters) it works all fine, after creating a new item the list is auto-merged and auto-refreshed, but when calling the first fill method the auto-merge is not being done after inserting (when deleting and updating the automerge works fine).
            The first fill method is sending an object parameter, this is an item selected from the sistemasList, there's a relation between these two, a Sistema has many Roles and a Rol has only one Sistema, so this fill method goes to the DB and fetches all the roles that belong to a certain Sistema (the selectedItem of the sistemasList).
            The second fill method fetches all the Roles in the DB no matter if they belong a to certain Sistema or not, this fill works perfectly fine, but the first one is not.

            Any ideas???
            • 3. Re: DataService fill method bug
              T._Ruggles Level 1
              That should just work. Can I see your client code?
              • 4. DataService fill method bug
                dimival Level 1
                You mean the Java Assembler?

                public Collection fill(List fillParameters) {
                List resultados = new ArrayList();
                if (fillParameters.size() > 0) {
                resultados = getServiceData().findRolesBySistemaId(((SistemaVO) fillParameters.get(0)).getSisId());
                }
                else {
                resultados = getServiceData().findAllRoles();
                }
                return resultados;
                }

                public void createItem(Object item) {
                getServiceData().save((RolVO)item);
                }


                I debugged my flex application and there is an UpdateCollectionMessage after the commit of the createItem( ) but for some reason the ArrayCollection doesn't detect it.
                Like i said this only happens after a createItem() when deleting or updating an item it works fine, refreshing the list.

                If i use the fill without extra parameters it works fine, i can insert and it is automerged and refreshed.

                • 5. DataService fill method BUG
                  dimival Level 1
                  Ok i found the reason the autoRefresh is failing and it's because sending an object as a parameter of the fill method is causing the bug.
                  On Flex i was doing the following:

                  dataService.fill (ArrayCollection, SysObj) //where SysObj is an instance of an AS class which has an equivalent Java class (managed and alias metadata)

                  and the equivalent Java Assembler code:

                  public Collection fill (List fillParameters) {
                  SysObj a = (SysObj) fillParameters.get(0);
                  List results = dao.findRoles (a.getId() );
                  return results;
                  }

                  As you can see i am sending an AS class (which is mapped to a Java class using the Remote alias metadata) to the fill method and then on Java i am casting this object and calling a DAO method passing the id of the object. After a createItem the autorefreshed is executed but the ArrayCollection on Flex is not autorefreshed, you need to call the fill method once again from the Flex code to see the new ArrayCollection.

                  I then changed my code to the following:

                  dataService.fill(ArrayCollection, sysId) //where sysId is the Id of the SysObj

                  on Java i did this:

                  public Collection fill (List fillParameters) {
                  List results = dao.findRoles (fillParameters.get(0));
                  return results;
                  }

                  With these modifications, that is sending an Integer value instead of an Object, the autoRefresh is executed and the ArrayCollection automerged and refreshed showing the new added Item.

                  So the thing (BUG) is that if you pass an ActionScript object as a parameter for the fill method, the autorefresh fails to notify the flex collection, but when sending a primitive object (integer, string, etc) then it works perfectly.

                  This is a BUG, right? if not, how do i need to do to send an AS object and make the autorefresh work ???
                  I do need to send the AS object (just in case you are thinking that i should only send the object Id) for business reasons, so is it possible???