My last Flex blog post demonstrated Flex as a ColdFusion client, a n-tier application using ColdFusion as the logic layer and Flex as the presentation layer. Here is another way to integrate Flex and ColdFusion; dynamically generated Flex.
Click on URL http://www.forta.com:8100/cf/flex/tree.cfm to see an example of a Flex tree. It is a really simple example, and mildly impressive at best. So why am I posting this? Look at the URL, it is a .cfm URL, not a .mxml url.
Christophe Coenraets posted a really useful entry on using the Flex JSP Tag Library so as to be able to generate MXML inline within a JSP page. (See http://www.markme.com/cc/archives/004021.cfm).
Can ColdFusion users do the same? Absolutely, that's exactly what the tree example is doing. ColdFusion can import and invoke JSP tags, and the Flex JSP tags are no exception.
Here is the CFML code used in this example:
<!--- Import Flex JSPs --->
<CFIMPORT TAGLIB="/WEB-INF/lib/flex-bootstrap.jar" PREFIX="mm">
<!--- Create tree XML --->
<CFSAVECONTENT VARIABLE="tree">
<node label='Option 1'>
<node label='Option 1.1'/>
<node label='Option 1.2'/>
</node>
<node label='Option 2'/>
</CFSAVECONTENT>
<!--- Page --->
<HTML>
<BODY>
<H1>Flex Embedded in ColdFusion</H1>
<!--- Start of MXML --->
<mm:mxml>
<mx:Application width="200" height="200" xmlns:mx="http://www.macromedia.com/2003/mxml">
<!--- Tree --->
<mx:XML id="myTree">
<!--- CF tree data --->
<CFOUTPUT>#tree#</CFOUTPUT>
</mx:XML>
<mx:Tree widthFlex="1" heightFlex="1" dataProvider="{myTree}"/>
</mx:Application>
</mm:mxml>
</BODY>
</HTML>
In this example I hard-coded the menu contents to keep things simple, but you can imagine using queries or CFCs or any CFML code here. This type of integration, being able to use both CFML and MXML together, makes it really easy to create ColdFusion/Flex applications.
is this tapping into my flash player?
thanks!
Tony, I installed Flex on top of JRun which is also running CFMX6.1. The flex-bootstrap.jar is part of Flex, and exposes the JSP tags which CF uses. There is nothing specific to CF about this, CF kind of gets this for free thanks to its support for JSP tag libraries. It's beautiful when stuff just works, huh? :-)
Also, you are doing a preso on Flex. Are we allowed to demonstrate flex? or do you have special permission? I want to beat you to presenting Flex for the first time at a UG (just kidding)
And no, I am first, so phhhbbbttthhhhh!!!! :-)
'Not to mention, its very easy to write bad code unintionally when
building Flex MXML widgets embedded in CFML code. If the resultant
MXML changes as per branching logic at runtime, you'd be recompiling
the swf output every time the runtime logic varies, a very expensive
operation.'
If 2 users would meet the same CFIF in a page serving flex conditionaly, will it recompile it every time or will it just output the .swf from the cache?
Kind regards
I can't have your example working, I installed CF7 + Flex 1.5 on Jetty, following the procedure described at http://www.macromedia.com/support/documentation/en.... I can run pure .mxml or pure .cfm but if I try your example, only the H1 tag will output :(
The console throws errors with NoClassDefFoundError :org/apache/axis...
Any idea?
Kind regards
When I try to use the cfimport tag to import the flex-bootstrap.jar file
<!--- Import Flex JSPs --->
<CFIMPORT TAGLIB="/WEB-INF/lib/flex-bootstrap.jar" PREFIX="mm">
I get the following error message.
Could not import the tag library specified by "/WEB-INF/lib/flex-bootstrap.jar".
The following error was encountered: Tag Library Descriptor not found. Please ensure that you have specified a valid tag library.
Note: I'm using CF702 with Flex2.0 on TomCat
The CFML compiler was processing:
* a cfimport tag beginning on line 11, column 2.
where can i find the tag library descriptor for this component.
--- Ben
If you find any workaround on that please let us know, as this is indeed very interesting! :-)
thanks!!