Using Flex to Access ShadoMX Variables
I got Flex to access Shado variables. It's quite easy.
Make sure that you turn on "Use J2EE session variables" option in CF Admin (under Memory Variables).
Here is the code for the flex page:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" initialize="initApp()">
<mx:RemoteObject id="sessionService" source="uosmx.app_templates.objects.reg" endpoint="@ContextRoot()/flashservices/gateway?">
<mx:method name="dump" result="handleDumpResult(event.result)" showBusyCursor="false" />
<mx:method name="login" result="handleLoginResult(event.result)"></mx:method>
<mx:method name="getShadoObject" result="handleShadoObjectResult(event.result)"></mx:method>
</mx:RemoteObject>
<mx:Script>
<![CDATA[
var username :String = "";
var password :String = "";
var userdisplayname :String = "";
var useruuid :String = "";
var useremail :String = "";
var userrightslist :String = "";
var userloggedin :Boolean = false;
var objectname :String ="";
function initApp():Void{
trace("Firing login method on sessionService");
//sessionService.dump();
trace("Firing dump method on sessionService");
}
function handleDumpResult(event:Object):Void{
var foo:Object = event;
trace("Received result from dump method of sessionService.");
for (var i in foo){
trace(i + " : " + foo[i]);
}
}
function login(username:String, password:String):Void{
sessionService.login(username=username,password=password);
}
function handleLoginResult(event:Object):Void{
trace("Received result from login method of sessionService.");
sessionService.getShadoObject(objectname="request.usercontext");
}
function handleShadoObjectResult(event:Object){
trace("Received result from getShadoObject");
username = login_username.text;
password = login_password.text;
userdisplayname = event.DISPLAYNAME;
useruuid = event.USER_UUID;
useremail = event.USER_EMAILADDRESS;
userrightslist = event.THISUSERRIGHTSLIST;
userloggedin = event.LOGGEDIN;
}
]]>
</mx:Script>
<mx:HBox id="mainHBox">
<mx:Panel id="userInfo" title="User Information" width="300">
<mx:Text id="info_useruuid" text="User UUID: {useruuid}"></mx:Text>
<mx:Text id="info_username" text="User Login: {username}"></mx:Text>
<mx:Text id="info_userdisplayname" text="User Name: {userdisplayname}"></mx:Text>
<mx:Text id="info_useremail" text="Email: {useremail}"></mx:Text>
<mx:Text id="info_userrightslist" text="Rights List: {userrightslist}"></mx:Text>
<mx:Text id="info_userloggedin" text="Logged in: {userloggedin}"></mx:Text>
</mx:Panel>
<mx:Panel id="loginInfo" title="Login" width="200">
<mx:Text text="Username: "></mx:Text><mx:TextInput id="login_username"></mx:TextInput>
<mx:Text text="Password: "></mx:Text><mx:TextInput id="login_password"></mx:TextInput>
<mx:Button id="login_button" label="Login!" click="login(login_username.text,login_password.text)"></mx:Button>
</mx:Panel>
</mx:HBox>
</mx:Application>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" initialize="initApp()">
<mx:RemoteObject id="sessionService" source="uosmx.app_templates.objects.reg" endpoint="@ContextRoot()/flashservices/gateway?">
<mx:method name="dump" result="handleDumpResult(event.result)" showBusyCursor="false" />
<mx:method name="login" result="handleLoginResult(event.result)"></mx:method>
<mx:method name="getShadoObject" result="handleShadoObjectResult(event.result)"></mx:method>
</mx:RemoteObject>
<mx:Script>
<![CDATA[
var username :String = "";
var password :String = "";
var userdisplayname :String = "";
var useruuid :String = "";
var useremail :String = "";
var userrightslist :String = "";
var userloggedin :Boolean = false;
var objectname :String ="";
function initApp():Void{
trace("Firing login method on sessionService");
//sessionService.dump();
trace("Firing dump method on sessionService");
}
function handleDumpResult(event:Object):Void{
var foo:Object = event;
trace("Received result from dump method of sessionService.");
for (var i in foo){
trace(i + " : " + foo[i]);
}
}
function login(username:String, password:String):Void{
sessionService.login(username=username,password=password);
}
function handleLoginResult(event:Object):Void{
trace("Received result from login method of sessionService.");
sessionService.getShadoObject(objectname="request.usercontext");
}
function handleShadoObjectResult(event:Object){
trace("Received result from getShadoObject");
username = login_username.text;
password = login_password.text;
userdisplayname = event.DISPLAYNAME;
useruuid = event.USER_UUID;
useremail = event.USER_EMAILADDRESS;
userrightslist = event.THISUSERRIGHTSLIST;
userloggedin = event.LOGGEDIN;
}
]]>
</mx:Script>
<mx:HBox id="mainHBox">
<mx:Panel id="userInfo" title="User Information" width="300">
<mx:Text id="info_useruuid" text="User UUID: {useruuid}"></mx:Text>
<mx:Text id="info_username" text="User Login: {username}"></mx:Text>
<mx:Text id="info_userdisplayname" text="User Name: {userdisplayname}"></mx:Text>
<mx:Text id="info_useremail" text="Email: {useremail}"></mx:Text>
<mx:Text id="info_userrightslist" text="Rights List: {userrightslist}"></mx:Text>
<mx:Text id="info_userloggedin" text="Logged in: {userloggedin}"></mx:Text>
</mx:Panel>
<mx:Panel id="loginInfo" title="Login" width="200">
<mx:Text text="Username: "></mx:Text><mx:TextInput id="login_username"></mx:TextInput>
<mx:Text text="Password: "></mx:Text><mx:TextInput id="login_password"></mx:TextInput>
<mx:Button id="login_button" label="Login!" click="login(login_username.text,login_password.text)"></mx:Button>
</mx:Panel>
</mx:HBox>
</mx:Application>
In line three, a call is made to a cfc: uosmx.app_templates.objects.reg. The code for the cfc is here:
<cfcomponent displayName="Registration" hint="Registration class for a new student">
<cffunction name="dump" access="remote" returntype="any">
<cfsavecontent variable="cookiedump">
<!--- <cfdump var="#session#"> --->
<cfdump var="#request.usercontext#">
<!--- <cfdump var="#application#"> --->
</cfsavecontent>
<cffile action="append" addnewline="yes" file="c:\flextext.htm" output="#cookiedump#">
<cfreturn request.userContext>
</cffunction>
<cffunction name="login" access="remote" returntype="any">
<cfargument name="username" required="yes" type="string">
<cfargument name="password" required="yes" type="string">
<cfset var stArgs = duplicate(arguments)>
<cfset stArgs.site = request.siteContext.dsn>
<cfset stArgs.performRedirect = false>
<cfif structKeyExists(request.userContext, "loggedin") AND NOT request.userContext.loggedin>
<cfset application.shado_obj_factory.get("shadomx.core.users.shado_int_users").actUserLogin(argumentcollection=stArgs)>
</cfif>
<cfreturn true>
</cffunction>
<cffunction name="getShadoObject" access="remote" returntype="any">
<cfargument name="objectname" required="yes" type="string">
<cfreturn evaluate(objectname)>
</cffunction>
</cfcomponent>
<cffunction name="dump" access="remote" returntype="any">
<cfsavecontent variable="cookiedump">
<!--- <cfdump var="#session#"> --->
<cfdump var="#request.usercontext#">
<!--- <cfdump var="#application#"> --->
</cfsavecontent>
<cffile action="append" addnewline="yes" file="c:\flextext.htm" output="#cookiedump#">
<cfreturn request.userContext>
</cffunction>
<cffunction name="login" access="remote" returntype="any">
<cfargument name="username" required="yes" type="string">
<cfargument name="password" required="yes" type="string">
<cfset var stArgs = duplicate(arguments)>
<cfset stArgs.site = request.siteContext.dsn>
<cfset stArgs.performRedirect = false>
<cfif structKeyExists(request.userContext, "loggedin") AND NOT request.userContext.loggedin>
<cfset application.shado_obj_factory.get("shadomx.core.users.shado_int_users").actUserLogin(argumentcollection=stArgs)>
</cfif>
<cfreturn true>
</cffunction>
<cffunction name="getShadoObject" access="remote" returntype="any">
<cfargument name="objectname" required="yes" type="string">
<cfreturn evaluate(objectname)>
</cffunction>
</cfcomponent>
You should place this cfc in the app_templates/objects directory of your site.
Also, for this to work, you need to make sure that you have Flex working with CF. I had blogged this this earlier. Also, make sure that you've:
a) Removed the flashgateway from the Jrun server instance on which you are running this.
b) Also, look at /WEB-INF/flex/flex-config.xml, the
<amf-gateway>{context.root}/amfgateway</amf-gateway>
Comments
There are no comments for this page as yet.
print page
