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: Where should data be stored  (Read 7950 times)
vladakg85
Full Member
***
Posts: 22


View Profile Email
« on: June 17, 2009, 06:30:05 »

Scenario: User type login data, proxy invoke loginMethod on server which after succesfull login return collection of user data (id, username, password, fname, lname, address, email etc.), now...
After succesfull login loginControll is removed and application is in new state, here I wan't to display userDetails but I don't know how :(. After login where should I store returned users data so that I can use them later, and how to retrive them when I need them?
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: June 17, 2009, 06:47:16 »

In a Proxy.

To retrieve from a Command, Mediator or another Proxy: facade.retrieveProxy(proxyName)

-=Cliff>
Logged
vladakg85
Full Member
***
Posts: 22


View Profile Email
« Reply #2 on: June 23, 2009, 11:43:59 »

loginUserData is always null when I try to call it from mediator :(


------------------------------
LoginCommand
:
public class LoginCommand extends SimpleCommand implements ICommand
{
override public function execute(notification:INotification):void
{
var myUser:User = notification.getBody() as User;
var loginProxy:LoginProxy;
loginProxy = facade.retrieveProxy(LoginProxy.NAME) as LoginProxy;
loginProxy.tryLogin(myUser.username, myUser.password);
}

}
LoginProxy
:
public class LoginProxy extends Proxy implements IProxy
{
public static const NAME:String = "loginProxy";


private var loginRemoteService:RemoteObject;

public function LoginProxy()
{
super(NAME, new User());


}

override public function onRegister():void
{
loginRemoteService = new RemoteObject("fluorine");
loginRemoteService.source = "BL.Sample";
loginRemoteService.LoginUserByEnteredData.addEventListener(ResultEvent.RESULT, onResult);
loginRemoteService.addEventListener(FaultEvent.FAULT, onFault);
}

private function onResult(evt:ResultEvent):void
{
data = evt.result as User;
sendNotification(ApplicationFacade.LOGIN_SUCCESFUL, loginUserData);
}

private function onFault(evt:FaultEvent):void
{
sendNotification(ApplicationFacade.LOGIN_FAILED);
}

public function get loginUserData():User
{
return data as User;
}

public function tryLogin(p1:String, p2:String):void
{
loginRemoteService.LoginUserByEnteredData(p1, p2);
}
}
Mediator
:
override public function handleNotification(notification:INotification):void
{
switch (notification.getName())
{
case ApplicationFacade.LOGIN_SUCCESFUL:
var uProxy:LoginProxy;
uProxy = facade.retrieveProxy(LoginProxy.NAME) as LoginProxy;
var u:User = notification.getBody() as User;
Alert.show("welcome: " + u.realName+ ", " + u.City);
break;
case ApplicationFacade.LOGIN_FAILED:
Alert.show("sorry pal, wrong password");
break;
}
}
Logged
vladakg85
Full Member
***
Posts: 22


View Profile Email
« Reply #3 on: June 25, 2009, 02:20:39 »

Ok, problem solved, my friend with more experience help :)

I made stupid mistake, I have wrong mapped User VO, instead this:
[RemoteClass(alias="BL.User")]
Now I have this:
[RemoteClass(alias="DemoFluorine.BL.User")]

Thats why service returned me ObjectProxy
Logged
Pages: [1]
Print