Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: strongly typed objects in array collection  (Read 16541 times)
PhoneTech
Newbie
*
Posts: 8


View Profile Email
« on: October 30, 2007, 02:45:33 »

I have a Java Swing GUI background using a framework (JGoodies) that is very similar to PureMVC and because of the good documentation, i choose to use PureMVC. But enough with the kudo's...

I have a remote service call to a Spring bean which returns a list of objects. With xdoclet 2 I created the VO objects to be used by PureMVC. The VO objects have a source reference to the java class.

My Proxy has an arraycollection as data value and this is filled nicely in the constructor. This works very well. however when I want to display the arraycollection in a DataGrid with no columns defined, I can only see 1 row with information about the arraycollection instead of the 5 items in the arraycollection. When defining the columns and their dataFields, no rows are shown.

I have been searching for hours on how to get the objects out of my arraycollection and on to the screen. Could anyone give me some tips to get me started?
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: October 30, 2007, 08:46:10 »

I'm assuming the use of FlexBuilder in this suggestion:

Place a breakpoint somewhere such as at the end of your startup command or wherever you know that the Proxy and Mediator will have been created and registered.

Then in the debugger variables view, drill to the facade reference.

You may need to click the down-arrow (options menu) on the right of the Variables view and select 'Flex: Show inaccessible member variables'.

Expand the facade variable to reveal the model, view, and controller.

Expand the model, then the proxyMap, and finally your proxy.

Examine the structure of the data variable. Then examine the structure of your variable that casts data to ArrayCollection. Are they the same? Did something that holds an ArrayCollection get cast to ArrayCollection get cast instead of the ArrayCollection itself?

If not, expand facade.view.mediatorMap, and within that find and expand your Mediator. Examine the viewComponent and drill to the datagrid if it is a child. Examine its dataProvider property. Is it the same as your (presumably at this point) well formed and populated ArrayCollection held by your Proxy? Is the memory address the same? Could it be that the Proxy's ArrayCollection was somehow transfomed on the way to being hooked up to the dataGrid?

Coming from Java, I'm sure you appreciate a good debugger. The nice thing about debugging a PureMVC app is once you get a reference to the facade, everything in the app is there in one cleanly navigable tree.

Hope this approach helps you to get to the root of the problem.

-=Cliff>
« Last Edit: October 30, 2007, 02:10:11 by puremvc » Logged
PhoneTech
Newbie
*
Posts: 8


View Profile Email
« Reply #2 on: November 01, 2007, 04:02:30 »

Thank you for your good reply. However, my Flex Builder 3 prevents me from debugging somehow. Even when I run the application server in debug mode, and start the form from application server, nothing happens when the code reaches the breaklines. I will look into it further later today.

Kind regards,

Bart
Logged
PhoneTech
Newbie
*
Posts: 8


View Profile Email
« Reply #3 on: November 02, 2007, 09:38:10 »

Ok, I got every thing setup correctly now, and it seems that value that holds an array collection is cast to an array collection resulting in a nested array colleciton.

In the Architecture 101 demo, values are added using addItem method. Should I do this as well?

:
package nl.qnh.qanban.model
{
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
import mx.rpc.remoting.RemoteObject;
import mx.utils.ArrayUtil;

import org.puremvc.interfaces.IProxy;
import org.puremvc.patterns.proxy.Proxy;

public class KanbanBoardProxy extends Proxy implements IProxy
{
public static const NAME:String = 'KanbanBoardProxy';

private var qanbanServiceRO: RemoteObject;

public function KanbanBoardProxy()
{
super(NAME, new ArrayCollection());
qanbanServiceRO = new RemoteObject("qanbanServiceRemote");
qanbanServiceRO.addEventListener("result", getKanbanBoardListEventHanlder);
qanbanServiceRO.getKanbanBoardList();

}

public function getKanbanBoardListEventHanlder(event:ResultEvent):void
{
kanbanBoards.source = ArrayUtil.toArray(qanbanServiceRO.getKanbanBoardList.lastResult);
trace(kanbanBoards);
}

public function get kanbanBoards():ArrayCollection
{
return data as ArrayCollection;
}

override public function getProxyName():String
{
return NAME;
}

}
}

What should I do to prevent this? I am still a novice concernign action script, but very eager to learn :)
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #4 on: November 02, 2007, 12:38:31 »

I believe you want to have your result handler do this instead:

:
public function getKanbanBoardListEventHanlder(event:ResultEvent):void
{
data = event.result;
trace(kanbanBoards);
}

-=Cliff>
Logged
PhoneTech
Newbie
*
Posts: 8


View Profile Email
« Reply #5 on: November 28, 2007, 11:18:44 »

Back again for one simple question.

I added an item to the database through the remote service. When I retrieve the list again, the data object is renewed, but the changes are not passed to listening components.

Is it better not to updatethelist from the server, but to add the user to the arraycollection manually? (this updates listening components :))
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #6 on: November 28, 2007, 01:42:49 »

Its important to remember that PureMVC does not rely on Flex binding to move data between Model and View.

When we distribute a reference to an ArrayCollection held by a Proxy and populate view components with that reference, the changes to items in that ArrayCollection are communicated to the various view components it has been made a dataProvider for automagiclly by Flex. 

However when you replace the ArrayCollection instance in the Proxy, no actor with a reference to the previous ArrayCollection is notified.

Ths means your Proxy should send a Notification when it replaces its data object, the ArrayCollection. 

Then, interested Mediators will receive the Notification and replace the previous reference used to populate their view components with the new one.

-=Cliff> 
Logged
PhoneTech
Newbie
*
Posts: 8


View Profile Email
« Reply #7 on: November 29, 2007, 05:12:41 »

I can see your point and PureMVC should not be responsible to manage the flex events.

But, because I am somewhat lazy and do not want to sendout notifications to every component mediator listening to the proxy I solved this a bit different :)

My remoteService returns an ID from the added object. In the event result handler I retrieve the object from the java backend and add it to the arraycollection.

But sending out refresh notifications is not really a big deal either. Which option is best?

I am planning to integrate messaging as well later. My proxyies will listen to incoming messages and will change the datamodel. Is it better to use notifications for this as well?
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #8 on: November 29, 2007, 07:16:43 »

Your solutione of just adding the item to the ArrayCollection makes the most sense.

In my previous response I just wanted to point out what needs to be done when the Proxy overwrites its ArrayCollection altogether, which depending on the situation, you may need to do.

It makes sense to take advantage of the tight ArrayCollection (and XMLListCollection) integration with Flex list controls wherever possible just as you have done here. Its just important to remember where the magic happens so that you recognise when to send Notifications and when you can rely on Flex to get display updates happening correctly.

-=Cliff>
Logged
PhoneTech
Newbie
*
Posts: 8


View Profile Email
« Reply #9 on: November 29, 2007, 07:24:55 »

Thanks for your quick and helpfull reply!. I really enjoy working with the PureMVC, especially with the expertise available on the forum.
Logged
Pages: [1]
Print