PureMVC Architects Lounge

Announcements and General Discussion => Getting Started => Topic started by: vladakg85 on June 17, 2009, 06:30:05



Title: Where should data be stored
Post by: vladakg85 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?


Title: Re: Where should data be stored
Post by: puremvc on June 17, 2009, 06:47:16
In a Proxy.

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

-=Cliff>


Title: Re: Where should data be stored
Post by: vladakg85 on June 23, 2009, 11:43:59
loginUserData is always null when I try to call it from mediator :(

(http://img37.imageshack.us/img37/4056/debug1.jpg)
------------------------------
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;
}
}


Title: Re: Where should data be stored
Post by: vladakg85 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