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 [2]
Print
Author Topic: EmployeeAdmin - A PureMVC AS3 / Flex Demo  (Read 49416 times)
marceloverdijk
Newbie
*
Posts: 6


View Profile Email
« Reply #15 on: July 23, 2008, 05:16:26 »

Yes updating the id is also vital for possible updating etc.

Thanks for your clarification.
Logged
marceloverdijk
Newbie
*
Posts: 6


View Profile Email
« Reply #16 on: July 23, 2008, 11:39:00 »

I have another question which is going through my head.
In the EmployeeAdmin only 2 commands are defined except the StartupCommand. In other places dispatchEvent(..) is used.

Is there a good rule when to use Commands and when to dispatch events. This does not seem to be consistent, I'm wondering what the difference is between the two.

Cheers,
Marcel
Logged
marceloverdijk
Newbie
*
Posts: 6


View Profile Email
« Reply #17 on: July 24, 2008, 12:06:42 »

Related to my above question here some exmaple.

The EmployeeAdmin uses a DeleteUserCommand which uses a proxy to delete an user and then sends a notification.

For adding an user - similar - logic (calling the proxy to add the user and sending a notification) is done in the UserFormMediator.

I'm wondering why ít's implemented in a different way.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #18 on: July 24, 2008, 05:02:04 »

To show that it can be done either way.

-=Cliff>
Logged
marceloverdijk
Newbie
*
Posts: 6


View Profile Email
« Reply #19 on: July 24, 2008, 06:25:27 »

OK, thanks again.
Logged
kouri
Courseware Beta
Full Member
***
Posts: 28


View Profile Email
« Reply #20 on: December 02, 2008, 09:02:24 »

Hi,

I adapted the EmployeeAdmin example to  remote data with AMFPHP and to deferred instanciation management (inspired by Slacker example)

My UserProxy now sends a RESPONSE notification to UserListMediator as soon as its RemoteObject brings back data and my users-getter is loosely typed:
:
public function get users():Object{
return data as Object;
}
Then UserListMediator handles this notification and feeds its datagrid through nearly same line as original:
:
userList.users=userProxy.users as ArrayCollection
Unfortunately my grid stay empty  :(

Weirdly, each of following statements works and fills my grid.
:
userList.userDatagrid.dataProvider=userProxy.users;and
:
userList.users=new ArrayCollection([{username: 'bigjoe', fname: 'john',lname:"Doe"...}]);
So, userList.users can receive an AC and userProxy.users is not empty and feed a dataprovider...

Can somebody help me understand why second can't feed first ?

Thx
Eric

« Last Edit: December 03, 2008, 05:24:58 by kouri » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #21 on: December 03, 2008, 06:27:40 »

The ball is being dropped somewhere; this sounds like a job thr the debugger.

Place a breakpoint on the line in the proxy where you first expect it to have data and run in debug mode. Look at the variables view.

Note: You may have to hit the little down arrow on the right side menu of the variables view and do Flex -> Show inaccessable members.

Does it have data? If so, step over until you get to the code setting the grids dataprovider. If not move your breakpoint farther back in the process and find out why the Proxy never gets its data. Did the service fail to retun the correct type? Inspect the ResultEvent.

Use the debugger, it'll be your best friend.

-=Cliff>
Logged
kouri
Courseware Beta
Full Member
***
Posts: 28


View Profile Email
« Reply #22 on: December 08, 2008, 06:27:47 »

The remote service returns an Array. So  the statement
:
userList.users=userProxy.users
works as soon as I type both parts as an Array.

Just need to know how to get an AC instead.

Thx again Cliff.

Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #23 on: December 08, 2008, 11:29:11 »

Ok, then in UserProxy, when you get the result, take the array, wrap it in an ArrayCollection and set that as the data property for the proxy. The users getter should by typed as ArrayCollection and return data as AC.

-=Cliff>
Logged
kouri
Courseware Beta
Full Member
***
Posts: 28


View Profile Email
« Reply #24 on: December 08, 2008, 09:20:51 »

 Unfortunately,Cliff, that's not as easy :-[

If I cast the result to AC in the resultHandler of UserProxy like that:
:
...
private var resultAC:ArrayCollection;
...
public function get users():ArrayCollection{
    return data as ArrayCollection;
}
...
private function onLoadAllResultHandler(event:ResultEvent):void {
     resultAC= event.result as ArrayCollection;
     setData(resultAC);
     sendNotification(USER_LIST_RESPONSE,resultAC);
}

then in UserList:
...
:
[Bindable] public var users:ArrayCollection;
and finally in UserListMediator:
:
...
override public function handleNotification( notif:INotification ):void{
   switch ( notif.getName() ){
      ...
      case UserProxy.USER_LIST_RESPONSE
         userList.users = userProxy.users as ArrayCollection
         break;
    }
    ...
    public function get userList():UserList{
         return viewComponent as UserList;
     }
}


there is no error but my datagrid doesn't display data anymore  ???

Logged
Jason MacDonald
Sr. Member
****
Posts: 243


View Profile Email
« Reply #25 on: December 09, 2008, 07:15:05 »

I haven't followed the whole thread, but if the original data is just a regular array you have to create a new ArrayCollection first, using your array as the data, then you can pass around the collection by casting it.

:
private function onLoadAllResultHandler(event:ResultEvent):void {
     resultAC= new ArrayCollection(event.result as Array);
     setData(resultAC);
     sendNotification(USER_LIST_RESPONSE,resultAC);
}
« Last Edit: December 09, 2008, 07:17:55 by jasonmac » Logged
kouri
Courseware Beta
Full Member
***
Posts: 28


View Profile Email
« Reply #26 on: December 09, 2008, 03:05:01 »

You got it, Jasonmac  !
A big thank to you too  :D

I didn't see that event.result has to be casted to an Array first,before being casted to an AC.

Now I get an AC as in original EmployeeAdmin demo. That's cool !


 
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #27 on: December 10, 2008, 06:49:27 »

Yes, this method does violate the encapsulation of the view component a bit as it it written, and it should be cleaned up. The method should actually be moved to the component itself.

-=Cliff>
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #28 on: February 17, 2010, 04:06:34 »

BTW, I've just updated this demo (to version 1.4), bringing it up to the latest best practices. Check the version.txt file included with the source for details. If you are the author of a port of this demo, there should be enough info in the version.txt file to guide you through the changes if you'd like to tweak yours up to spec.

Cheers,
-=Cliff>
Logged
Pages: 1 [2]
Print