I'm hitting a wall on a requirement for a Flex application which utilizes the LCDS version included with ColdFusion.
I have the project setup to use DAO's, Assemblers and ValueObject (cfc's) which I call from Flex via DataService implmentation and the fill(), getItem(), etc... methods.
I need to setup my ColdFusion layer to access multiple datasources from the same Flex application. However, because of the way LCDS gets called from Flex, it doesn't seem that Application or Session variables in ColdFusion persist when I set them. I was thinking I could just have the HTML (cfm) wrapper page for my Flex application set that, but it is not recognized when I go to make a fill or get call against the assembler.
I thought about passing the datasource as a parameter each time a call is made, but while that would work when I initiate fill and get methods, the sync methods are "invisible" and I wouldn't be able to append an argument to them.
So my issue is... how do I go about having ColdFusion read a dynamic variable to define it's datasource?
Thanks in advance for the help.
I am sorry I cannot answer your question but I suggest you post the question to the ColdFusion forum.
Tom Jordahl provided the answer on this for me. Here's the solution:
1) Prior to implementing this solution, it's important to realize that because LCDS manages the data, switching datasources dynamically could potentially cause issues if there is overlap between identifiers on the records you are retrieving. In my case, I'm using GUID fields as primary key and identifiers in my destinations, so this is not a problem. However, for example, if you were to use an incrementing integer for the identifier, then you could feasibly have LCDS managing a record, which would match identifiers with a record if you switched datasources on the fly.
2) I'm using ColdFusion as my middle-tier layer, but this could be applied to any form by accessing the flex.messaging.FlexContext class within your solution of choice.
3) The solution involves extracting the ID value of Flex client which makes calls against your Destination. Grab the identifier by calling FlexContext.getFlexClient().getId() to get a unique key for the "session". I use the term "session" loosely, as it's really just representative of the particular swf instance which has been loaded with your Flex Application. However, the ID doesn't change and persists across all calls you make against your destinations.
4) On application load, make a call to your CF layer which gets the ID, and sets it to the Application scope of the CF server as follows:
<cffunction name="set" access="remote">
<cfargument name="datasource" type="string" required="yes" default="">
<cfset var clientID="">
clientID = CreateObject('java', 'flex.messaging.FlexContext').getFlexClient().getId();
APPLICATION[clientID] = arguments.datasource;
The function above receives a unique string which I want to be my datasource of choice. You could call this "set" function again anytime to reset the Application variable for this "session".
5) The only other thing to do, is now access this Application variable for each datasource.
6) The last consideration is that each connection that is made via Flex will be setting a new variable in the Application scope on the Coldfusion server. This is a pretty minor concern for me, and I'll just run a schedule to clear the Application scope once a day, but if you have a high volume of users, a better solution would have to be found.