Is this Flash a Little Brighter? (cont.)

Integrating Flash with the ColdFusion Server
In the past, ColdFusion was a proprietary application server with an easy-to-use server-scripting environment. With ColdFusion MX, Macromedia threw out the proprietary server and replaced it with industry standards. ColdFusion MX provides a rapid server-scripting environment that deploys to any standard J2EE application server, and provides interoperability with .NET through Web services and COM.

ColdFusion scripts and components dynamically compile into Java classes and are deployed into a J2EE container, enabling a much broader group of RAD and scripting developers to easily construct server-side applications, but still benefit from the standards support, integration with, and scalability of J2EE. You can think of ColdFusion MX as an "ease of use layer" on top of the Java platform.

ColdFusion Components
The employee directory example in the Remoting section of this article uses a new feature in ColdFusion MX called ColdFusion Components, or CFCs. As we developed ColdFusion MX, we wanted to help take scripting-level Web application development forward without forcing developers to become full object-oriented programmers or requiring the use of system programming languages such as Java and C#.

In particular, as the Internet moves to Web services and rich clients, scripting developers need to move away from the poor architectures of the first generation of Web applications, where business logic, presentation logic, and data access were all assembled together in pages and templates, creating a reuse nightmare and limiting application scalability.

To accomplish this separation, we introduced CFCs, which provide a script-based and declarative model for defining services using simple text-based templates. These services not only can be consumed as objects from ECMAScript-like languages, but are also exposed as Web services using SOAP and WSDL, and to Flash Player through Remoting. The benefit is that scripting developers can participate in well-designed architectures without having to become full-on enterprise middleware developers.

A very basic component that provides an echo of a helloworld string would look like this:

<cfcomponent>
	<cffunction name="HelloWorld">
	<cfargument name="theString">
		<cfscript>
		Echo = "#arguments.theString#";
		return Echo;
		</cfscript>
	</cffunction>
</cfcomponent>
The actual name of the component is based on the filename, much like a Java class file. This simple component provides one function, which takes a string as an argument and returns the string to the caller.

The employee directory example defines an EmployeeDirectory.cfc document, which contains several functions: GetDepartments, GetEmployees, and GetDetails. If you look at the GetEmployees example in isolation, you can see all the code required to provide the server logic:
<cfcomponent>
 <cffunction name="searchDirectory" access="remote" returnType="query">
		<cfargument name="firstName" type="string">
		<cfargument name="lastName" type="string">
		<cfargument name="department" type="string">
				
		<cfquery name="q" datasource="exampleApps">
			
			
		SELECT tblEmployees.FirstName, 
				tblEmployees.LastName, 
				tblEmployees.EmployeeID, 
				tblDepartments.DepartmentName
		FROM tblEmployees, tblDepartments
		WHERE tblEmployees.DeptIDFK = 
tblDepartments.DepartmentID
		AND tblEmployees.firstName like '#firstName#%' 
		AND tblEmployees.lastName like '#lastName#%' 
		AND tblDepartments.DepartmentName LIKE '#department#%'
	  ORDER BY tblEmployees.LastName, tblEmployees.FirstName

		</cfquery>

		<cfreturn q>
			
   </cffunction>
</cffunction>
In this CFC, you can see a few additional things. The first is that the cffunction tag code defines two additional attributes, both of which are required to use the component through Macromedia Flash or SOAP. One is the "access" attribute, which is set to "remote"—this lets ColdFusion know that this component function can be accessed remotely, including from SOAP or Macromedia Flash. The "returntype" attribute sets the datatype that the function returns to the caller. In this case, the return type is a database query, which is a built-in type in ColdFusion and Flash Remoting.

Additionally, you can see that we've specified the data types of the required arguments, also necessary for proper WSDL and SOAP bindings. Finally, we're using the cfquery tag, which is a powerful tag that encapsulates all the complexities of using the JDBC APIs. We then return the query to the client using the cfreturn tag.

With the additional meta-data provided here, the CFC can be self-describing—making it easy for design-time tools and for Web services introspection using WSDL. You can get the documentation by simply pointing to the CFC using a web browser. That request returns auto-generated documentation on the component's interface. Likewise, you can append ?wsdl to any component URL and get the WSDL definition—hence any tool that can import and use WSDL for generating Web service client proxies can easily use any CFC that you've built.

Building CFCs and Server Logic
While you can create ColdFusion Components (CFCs) using any text editor, Macromedia has introduced a new version of its development environment, Dreamweaver MX. Just as Macromedia Flash and ColdFusion have undergone significant transformations in their roles, positioning, and capabilities, so too has Dreamweaver. While it continues to have great visual design and site development features, Macromedia added a broad range of coding and application development features. We've merged in the major features of HomeSite, Dreamweaver UltraDev, and ColdFusion Studio into a new integrated workspace.

We've focused particular attention on providing strong support for server-side development using ColdFusion MX. Dreamweaver MX provides full language support, including tools for code hinting, property inspectors, debugging, etc., but also specific tools for database, component, and Web service development. One of the central tools is the ColdFusion Component browser, which allows you to easily create and use CFCs. Dreamweaver MX also includes a Web services browser for easily working with SOAP Web services.



Client/Server Communications

Moving Away from the Document-based Web

Introduction Integrating Flash with the ColdFusion Server
Client/Server Communications Moving Away from the Document-based Web


 




A Hard-Working Player

Macromedia Designer and Developer Center

DevX Web Development Zone

All Flash articles on DevX
 TALK BACK
Is Jeremy's notion of "rich" Internet applications a peek into the future or just a technique he's using to legitimize a larger importance for Flash? As a Web developer, have you taken a renewed interest in Flash since the MX release or is it still just a plaything for high-tech animators? Tell us in the talk.editors.devx discussion group.
Click here to Join




 
Sponsored Links

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map
Jupiterweb networks

internet.comearthweb.comDevx.comClickZ

Search Jupiterweb:

Jupitermedia Corporation has four divisions:
JupiterWeb, JupiterResearch, JupiterEvents, and JupiterImages

Copyright 2004 Jupitermedia Corporation All Rights Reserved.
Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Jupitermedia Corporate Info | Newsletters | Tech Jobs | E-mail Offers

Copyright Information/Privacy Statement