| Package | com.lafabrick.reflex.controller |
| Class | public class BaseController |
| Inheritance | BaseController flash.events.EventDispatcher |
Creation of the data object UserDo>
package dataObject
{
[Bindable]
[RemoteClass(alias="User.UserDo")]
public class UserDo
{
public function UserDo()
{
}
public var login:String;
public var name:String;
}
}
Creation of data model UserModel
package model
{
import com.lafabrick.reflex.model.BaseModel;
import dataObject.UserDo;
public class UserModel extends BaseModel
{
[Bindable]
public var userLogged:UserDo;
}
}
Creation of a basic controller UserController
package controller
{
import com.lafabrick.reflex.controller.BaseController;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
public class UserController extends BaseController
{
public function login( log:String, pass:String ) : void
{
// execute thedistant method "login", and associate the handlers functions
executeMethod( "login", onLoginResult, onLoginFault, log, pass);
}
public function onLoginResult( event:ResultEvent ) : void
{
trace("result OK : let's gamble !");
(ModelLocator.getModel( UserModel ) as UserModel).userLogged = event.result as UserDo;
}
public function onLoginFault( event:FaultEvent ) : void
{
trace("bad result ..."+event.fault);
}
}
}
Implementation
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
xmlns:controller="controller.
xmlns:model="model.>
<mx:RemoteObject id="remoteUser" destination="javaFacadeUser" showBusyCursor="true" />
<controller:UserController id="userControl" service="{remoteUser}" />
<model:UserModel id="userModel" />
<mx:VBox>
<mx:TextInput id="login" />
<mx:TextInput id="password" displayAsPassword="true" />
<mx:Button label="connect" click="{userControl.login( login.text, password.text )}" />
<mx:Label x="208" y="44" text="User Name : {userModel.userLogged.name}"/>
</mx:VBox>
</mx:Application>
See also
| Property | Defined by | ||
|---|---|---|---|
| eventDispatcher : EventDispatcher
Defines an event dispatcher for this controller
In case this dispatcheur is not defines, the distribution channel is the one by default : the controller himself. | BaseController | ||
| service : AbstractService
Defines the AbstractService for this controller
This property must be defines for the functioning of the controller | BaseController | ||
| Method | Defined by | ||
|---|---|---|---|
|
executeMethod(method:String, resultFunction:Function, faultFunction:Function = null, ... args):void
Execute a specific method, with some arguments
| BaseController | ||
| eventDispatcher | property |
eventDispatcher:EventDispatcher [read-write]Defines an event dispatcher for this controller
In case this dispatcheur is not defines, the distribution channel is the one by default : the controller himself.
To define a dispatcher of event allows for example to obtain a common channel of discussion between the controller and the model
public function get eventDispatcher():EventDispatcher
public function set eventDispatcher(value:EventDispatcher):void
| service | property |
service:AbstractService [read-write]Defines the AbstractService for this controller
This property must be defines for the functioning of the controller
Implementation public function get service():AbstractService
public function set service(value:AbstractService):void
| executeMethod | () | method |
public function executeMethod(method:String, resultFunction:Function, faultFunction:Function = null, ... args):voidExecute a specific method, with some arguments
Parametersmethod:String — the name of the method
|
|
resultFunction:Function — the result handler
|
|
faultFunction:Function (default = null) — (default null) the fault handler. If null : the controller dispatch the faultEvent
|
|
... args — arguments to pass
|