Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

I Need Assistance with a Hierarchical Collection

Avatar

Level 2
Hello,



I have three collections, A, B, and C. B is a collection
contained within A, and C is a collection contained in B.



When I add a new item to collection C, the item is
temporarily added to the collection correctly and then the
collection is quickly replaced with the last item added. I have
come to this conclusion after watching all items(mutiple items) of
collection C being displayed in a DataGrid correctly only to have
them replaced within a second with the last added item only.



I have modeled the application after the "Contact" sample
with Assemblers, DAOs, config files, etc. If anyone has any ideas
on how to correct this, I would appreciate it. I think it is
probably a setup issue within FDS XML files or something simple,
but I have tried multiple changes with no luck.



Thanks!
1 Accepted Solution

Avatar

Correct answer by
Level 2
Instead of using read-only=true, I was able to use lazy=true
and solve the problem. Thanks again for your time. With your help,
I was able to gain a better understanding of how FDS handles these
collections

View solution in original post

9 Replies

Avatar

Level 3
Hello



Need more information from it. What are the associations
among Collection A, B and C? How do you add item to collection C?





Thanks



William Chan

Avatar

Level 2
Here are some code snippets. Please let me know if you need
additional information.



Another interesting thing I've seen is the code works
correctly if I wait several minutes between adding new players. It
seems to be some type of timing issue in FDS. Thanks!



Load the collections...



private function initComp():void {

parties = new ArrayCollection();

dsParties = new DataService("partyList");

dsParties.addEventListener(MessageEvent.RESULT,
resultHandler);

dsParties.fill(parties);

}



private function resultHandler(event:ResultEvent):void {

dgParties.selectedIndex = 0;

party = Party(parties.getItemAt(0));

tables = party.tables;



dgTables.selectedIndex = 0;

table = Table(tables.getItemAt(0));

players = table.players;

}







Add a new player...



private function addPlayer():void {

var tmpPlayer:Player = new Player();



tmpPlayer.playerId = 22;

tmpPlayer.playerName = "Johnny";

tmpPlayer.tableId = 1;

tmpPlayer.startingBalance = 100;

tmpPlayer.seatNum = 1;



players.addItem(tmpPlayer);

}

Avatar

Level 3
Not sure what your assembler code is. However, it looks like
you persist your player on the player assembler. What I mean you
don't need any player data send to the table assembler to update
table's player. There is a setting in association definition called
read-only. Try set it to true in your table assembler's players
association. By setting this, FDS can determine your creation
sequence



William Chan

Avatar

Level 2
Are you referrig to the setup in the
data-management-config.xml file? Assuming it is, I have tried the
following and it did not work. Is this setup as you suggested? Once
again, thank you very much for your time!



<metadata>

<identity property="tableId"/>

<one-to-many property="players" destination="playerList"
read-only="true"/>

</metadata>

Avatar

Level 3
Hi,



Yes, it is what I mean. I think it should be configuration
issue, I tried something similar and it worked. Can you send me
your destination definitions to me wichan@adobe.com? I would like
to give it a try

Thanks



William

Avatar

Correct answer by
Level 2
Instead of using read-only=true, I was able to use lazy=true
and solve the problem. Thanks again for your time. With your help,
I was able to gain a better understanding of how FDS handles these
collections

Avatar

Level 3
Hello,



I was over looked the problem. I found that your player
contain tableid. In object oriented FDS, it works with object not
its id

I just tried your scenario, it worked for me. Your player
should not contain tableid. I can email my application for you as a
sample



William Chan

Avatar

Level 3
hello



The followings are my class definitions

package

{

import flash.net.registerClassAlias;

import mx.collections.ArrayCollection;

import mx.data.IManaged;

import mx.data.utils.Managed;



[RemoteClass(alias="dataservice.associations.lvl3.Party")]

[Managed]

public class Party

{

public var id : uint;

public var name : String;

public var tables: ArrayCollection;

}

}



package

{

import flash.net.registerClassAlias;

import mx.collections.ArrayCollection;

import mx.data.IManaged;

import mx.data.utils.Managed;



[RemoteClass(alias="dataservice.associations.lvl3.Table")]

[Managed]

public class Table

{

public var id : uint;

public var name : String;

public var players: ArrayCollection;

}

}



package

{

import flash.net.registerClassAlias;

import mx.collections.ArrayCollection;

import mx.data.IManaged;

import mx.data.utils.Managed;



[RemoteClass(alias="dataservice.associations.lvl3.Player")]

[Managed]

public class Player

{

public var id : uint;

public var lastname : String;

public var firstname : String;



}

}

Avatar

Level 3
My function to add player

public function createAssociationsByObjectGraph():void

{

party = new Party()

party.name = "party1";

party.tables = new ArrayCollection();

party.tables.addItem(new Table());

party.tables.addItem(new Table());



party.tables.getItemAt(0).players = new ArrayCollection();

player = new Player();

player.firstname = "Apple";

player.lastname = "Red";

party.tables.getItemAt(0).players.addItem(player);

player = new Player();

player.firstname = "Bananna";

player.lastname = "Yellow";

party.tables.getItemAt(0).players.addItem(player);



party.tables.getItemAt(1).players = new ArrayCollection();

player = new Player();

player.firstname = "Orange";

player.lastname = "Orange";

party.tables.getItemAt(1).players.addItem(player);

player = new Player();

player.firstname = "George";

player.lastname = "Lucas";

party.tables.getItemAt(1).players.addItem(player);

ptDS.createItem(party);

ptDS.commit();

}



public function addPlayer():void

{

player = new Player();

player.firstname = "George";

player.lastname = "Lucas";


parties_dg.selectedItem.tables.getItemAt(1).players.addItem(player);

ptDS.commit();

}



]]>

</Script>

<Button click="createAssociationsByObjectGraph()"
label="CreatePartyTablesPlayers"/>

<Button click="addPlayer()" label="addPlayer"
enabled="{parties_dg.selectedItem != null}"/>