CFCs with Flex - Should I Break The Rules?

I've been working on a personal project in my "spare time" (ie, evenings til way past my bed time) that has me rethinking some "best practices" for CFCs. The project is mostly Flex, but some traditional CF is sprinkled in where it makes sense. The challenge I've been facing is determining how to keep my CFCs from interacting with shared scopes (like application, session). The more I think about it, the more it seems to make sense to "break the rules" when it comes to Flex.

From what I've learned, the main reason to avoid accessing shared scopes from your CFC is that it makes your component less portable. In the case of a Flex application, if the purpose of my CFC is to solely provide transactions for that application, do I really need the component to be portable? Maybe. But as I said I'm struggling with alternatives. For example, one of the methods in my CFC returns a string of HTML. The HTML will not be Flex safe so I can not use Flex to display the result. Instead, on result of the remoting call I'd like to launch a new window that will display the HTML. To me the perfect solution would be to store the HTML in an array of structures (or struct of structs) in the session scope, with each structure containing a uuid corresponding to the given HTML. Then the remoting call would return the uuid, passing it along to the new window via the url. The new window would display the appropriate HTML from the session structure based on the uuid passed. As I said, to me it's a perfect solution. My method would be putting data into the session scope, rather than querying the scope which would preclude that my app is relying on specific session data to exist (therefore reducing portability). Is this a bad thing?

I'm sure there are other CFers out there like me who are just getting their feet wet with Flex. What do you think? How would you handle this case? The only other alternative is to make the HTML Flex safe, but I really don't want to go down that road (though it could easily be done). Users of this product are very familiar with the HTML formatting and would not likely be too happy with the change.

P.S. Not to get all prophetic, but I promise that this project is going to be very helpful to many of you CFers out there.

Comments
What I do is keep my CFCs pure and build one CFC that acts as the proxy. It "breaks" the rules and is the main thing Flex/Spry calls.
# Posted By Raymond Camden | 11/3/06 9:13 AM
Makes sense. So build the cfc to return the HTML string, and then Flex calls a proxy which invokes the method and writes to the session scope. OK, I'm happy with that.

Does it make sense then to store the base cfc in the application scope so that the proxy does not have to invoke it with each call?
# Posted By todd sharp | 11/3/06 9:20 AM
Sure. My proxy cfc breaks ALL the rules. So it uses app.somecfc.foo() for example.
# Posted By Raymond Camden | 11/3/06 9:21 AM
Forgot to sub. :)
# Posted By Raymond Camden | 11/3/06 9:21 AM
Grrrr.....Everytime I have a good post, someones blog pukes into MXNA and shoves my post down to page 3. :)
# Posted By todd sharp | 11/3/06 9:39 AM
What Ray said! I thought this was a pattern called a Facade? I've also heard the term "service object" to refer to this approach.

In normal situations I wouldn't be outputting HTML in my 'model' code.

After all is said and done, rules are relative.
# Posted By Jeff Houser | 11/3/06 10:37 AM
"In normal situations I wouldn't be outputting HTML in my 'model' code. "

Agreed. Actually, it's not directly 'outputting' but retrieving and returning the HTML as a string. Would that technically still be breaking the 'no view in the model' rule?

There is an alternative that I am considering (which still requires the proxy, or facade). Haven't made the final decision, but if I told you the circumstances than I'd be letting the proverbial cat out of the bag. Not that this project is all THAT, but.....
# Posted By todd sharp | 11/3/06 11:19 AM
That's it, I can't take it anymore. I'm taking half a vacation day and going home to work on this! Too many thoughts racing through my head! ;)
# Posted By todd sharp | 11/3/06 11:30 AM
That is a distinction I didn't catch initially (but should have). It is an important one to make.

As long as you separate your processing from your display elements, I don't have a problem returning HTML from a method.

Although, I wouldn't want to combine a method that both processes data and format it.
# Posted By Jeff Houser | 11/3/06 11:57 AM
curious as to what you're storing in session vars? most of what i used to stick there is now down in the flex client.
# Posted By PaulH | 11/4/06 7:03 AM
I can't speak for Todd, but...

I've had situations where queries will filter data based on the user's login credentials. In CF, the login credentials would be stored in some sort of session variable and queries filtered accordingly.

With the Flex Front End, I used a Facade (Or is service layer the right term?). After login, a 'sessiontoken' is passed back to the Flex client. That value is passed to each remoting call as an argument.

Now that I say that out loud, I think i was storing the relevant server-side-session info in the application scope, and loading it up as needed based on the sessiontoken, which isn't use of the session scope at all.
# Posted By Jeff Houser | 11/4/06 7:58 AM
The data that is going in the session scope will be utilized later by CF, not Flex (I'm really loving how nicely the two play together). So I think it's the right place to put it. But tell me more Paul, how are you doing that? Are you just storing things like authentication information, etc in the _global scope, or is there something else I'm not aware of.

An early release of the project should be good to go next week (assuming I can wrap some things up tommorrow). Keep an eye out here and in RIAForge!
# Posted By todd sharp | 11/4/06 1:32 PM
different sort of app, a front end to a web-based GIS (java) that we talk to w/CFCs. normally we'd store the data we needed to control the server GIS in session vars but we've moved pretty much all of that into classes/objects on the client for it to maintain & manipulate. cf uses the data but it's modified in the client & sent back to cf.

this helped simplify things cf side & seems to work a bit better w/this particular GIS--it's very tempting to maintain its objects in session vars but it gets cranky when it's used all day long like that and "normal" GIS apps tend to be used that way. storing it's normal "session" bits in the flex client helped us remove that temptation ;-)
# Posted By PaulH | 11/4/06 8:47 PM
I'm officially releasing tomorrow, but if you guys want a sneak peek check it out here: http://cfsilence.com/cfcFlexplorer/Flex/bin/cfcFle...
# Posted By todd sharp | 11/5/06 8:17 PM
Looks cool (and useful) Todd. If it was possible to pass in arguments when invoking a method on a component would make it perfect :)
# Posted By Trond Ulseth | 11/6/06 3:56 AM
It is possible Trond!! Click in the param grid, the value column is editable!
# Posted By todd sharp | 11/6/06 5:21 AM
Then I've got nothing left but to give two tumbs up :)
# Posted By Trond Ulseth | 11/6/06 8:33 AM
A bit late for a comment, but I've only just seen the light!

I've been doing remoting in Coldfusion Flash (Flex 1.5) forms for some time now, and the way I'd always set up my CFC's was as Ray Camden suggests: storing them in the application scope and using a lightweight proxy cfc to return the results of those methods.

However, all the Flex > Coldfusion integration suggests you create bindable mappings to cfc's in AS classes.

Doing this makes your Flex apps less portable as it requires Coldfusion at the backend. So yes... break the rules!
# Posted By Dan L | 5/7/07 5:28 PM

Calendar

Sun Mon Tue Wed Thu Fri Sat
     12
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31       

Subscribe

Enter your email address to subscribe to this blog.

Tags

actionscript ajax blogging cfsnippets coldfusion flash forms flex funny stuff misc model-glue off topic personal project learn slidesix sql

Recent Comments

Adding Auto Generated Code Downloads to BlogCFC
ada5fsa said: http://www.mountwashingto... http://extjs.com/forum/me... h... [More]

BlogCFC Survey #2
ada5fsa said: http://www.mountwashingto... http://extjs.com/forum/me... h... [More]

Most Difficult Captcha Of All Time
kokkooo said: [url=http://synchrophase.info/...]消費者金融 ブラック[/url] [url=http://geji-geji.com/]消費者金融ブラック[/url] [url=http... [More]

Most Difficult Captcha Of All Time
kokkooo said: <a href="http://synchrophase.info/...">消費者金融 ブラック</a> <a href="http://gej... [More]

Using A PlayStation 2 HDD In Your PC
Vodin said: Well dang. Thanks man, my uncle who owns a Video Game shop had a PS2 harddrive in the junk box, I sn... [More]

RSS


coldfusionbloggers

FullAsAGoog MXNA

Consumed By Feed-Squirrel.com