Welcome!

Adobe Flex Authors: Matthew Lobas, PR.com Newswire, Shelly Palmer, Kevin Benedict

Related Topics: Adobe Flex, ColdFusion

Adobe Flex: Article

Streamlining Application Development Using Struts in ColdFusion

ColdFusion MX supports Java objects and servlets in a big way

Although earlier versions of ColdFusion supported Java objects and servlets to some degree, ColdFusion MX does so in a big way. This support opens up commercially available libraries to ColdFusion developers that were previously only available to J2EE shops. Moreover, you can now draw from an immense library of free code from within the Java open-source community. This availability greatly enhances the features of your own applications and speeds your ColdFusion-based solutions to market. Use these objects to provide back-end processing or user-interface functionality, or simplify coding CFM pages by supplementing ColdFusion functions and tags with Java TagLibraries.

Of particular note is how ColdFusion MX hosts and runs the Apache Jakarta Project's Struts Action servlet. By implementing Struts, ColdFusion MX offers a Model-2 Model-View-Controller (or MVC) environment for ColdFusion applications. This article is based on an implementation that uses ColdFusion MX Enterprise Edition on a Windows server. ColdFusion MX Enterprise Edition includes an embedded J2EE server based on Macromedia JRun. In addition to hosting ColdFusion pages, Enterprise Edition can host JSPs and servlets. This article is also applicable to users running ColdFusion on third-party application servers, although directory and filenames will vary somewhat.

First I give a brief description of my recent project, which shows how Struts and other Java objects provided a timesaving solution to a ColdFusion project. Next I explain MVC architectures so that you can define the role that Struts plays in your application's architecture. Then you learn how to transition your own development into a Struts framework. Finally I give you a sample application to help you get started using Struts in your own environment. (Code for this article can be downloaded from http://macromedia.com/devnet/coldfusion/articles/struts.html.)

Background: Saving Time with Struts
My Company: I work for a firm that creates websites and web applications for a wide range of businesses. We support many technologies, including Java and ColdFusion. On Java projects, we capitalize on open-source projects to speed solutions to market. Over the years, we have accumulated a large library of Java applications, objects, and services.

In the Java arena, we have adopted the Struts framework for our web services. By using Struts to implement a true Model-2 MVC architecture, we can split work among our various groups. Our layout group is fluent in designing dazzling layouts using Macromedia Flash. Our business managers design conceptual business objects and workflow. Our developers use Struts to create in code the objects and flow described by the business managers. While the members of each group have great talents in their assigned areas, they require a cursory understanding of the others' ingredients to a web-based application.

Our Client: One recent client was an internal ColdFusion development shop for a large association of plastic surgeons. Their task was to create web-based services for their membership. The members use these services to promote their private practices to the public. The success of these developers is measured by the number of referrals that are driven by the website to the doctors' private practices. To do this, the association strives to be a clearinghouse from which potential patients can find the best doctor for their needs.

They run their website on Windows servers running ColdFusion MX Enterprise Edition. (They also happen to run CommonSpot, a content management package from PaperThin. They often import ColdFusion pages into CommonSpot for consistency with the rest of the site. However, CommonSpot integration is beyond the scope of this article.)

The Project: We had to create private photo galleries that users could access from a doctor's personal page. Doctors publish their most successful procedures using before-and-after photographs along with a description of the procedure. The reason for this is so that the public will view these images and be encouraged to contact the doctor's office for a consultation.

In addition, the association wanted to offer a general-purpose gallery to the public. By drawing customers to the site, the association would lead patients to a doctor's private page and hopefully generate a referral. This general gallery would be a subset of the best examples found among the members' private galleries.

This project offered us many challenges. First of all, the images were categorized by procedure, each of which had a unique HTML form to describe the patient, treatment, and results of the surgery. This form needed to be converted into a descriptive paragraph suitable for public viewing. Some form of template-technology would be required for that conversion.

Second, the images submitted by the members were typically simple downloads from a digital camera. These images came in various dimensions and resolutions and needed to be resized to standard dimensions before being stored on the servers. Additionally, photos needed to be watermarked with some sort of copyright text so discourage web surfers from appropriating them for their own uses.

Third, we needed to build in all the sorts of features you expect to find in a good online photo-gallery service: grouping, indexing, filtering, and so on.

The ColdFusion and Struts Solution: As with any business, competitive concerns and published timelines required our client to roll out these new services quickly and reliably. The services also needed to match the look and feel of the rest of the website. In addition, the workflow was still being "worked out" as development began.

By using Struts, we enjoyed all the benefits of MVC architecture: Our layout team started designing the pages that reflected the look and feel of the existing ColdFusion MX site while our developers created the Beans that maintained the photo gallery pages. They also started building the generic structures for the procedure forms. We created and modified the process flow through simple modifications to the Struts configuration file, and each team created independent timelines and contributed pieces to the project as they became available.

Java object support proved to be a great timesaver. In our private libraries, we already had a Java object that used the Graphics2D class to quickly complete the image-modification features. We implemented Apache Velocity (http://jakarta.apache.org/velocity/)to create the paragraph templates in record time. From an earlier contract, we already had a skeleton Struts service for creating a website photo gallery. In all, ColdFusion's support for Java and Struts allowed us to reuse code and work in parallel, effectively halving the time to complete the job.

(In all fairness, Macromedia technologies alone could have solved most of our requirements. ColdFusion pages, ColdFusion components, and Macromedia Flash components offer all the functionality we required. However, the ability to reuse open-source code, not to mention mine our private libraries, motivated many of our choices.)

Examining the Struts Framework's Usefulness
To understand what Struts is, it helps first to review the terms defining the Model-View-Controller (MVC) approach to application development (see Figure 1). When creating an application, the Model represents the information‹the logic‹that connects the information. To a Java developer, these roles are implemented by the storage media (such as database tables or data files) and the Beans that maintain them. To a ColdFusion developer, the model is supported by ColdFusion components and data sources.

The View is the interface used to present the model to users, or obtain input to maintain that model. To a web developer, this View is passed between web browsers and web servers as HTML pages and HTTP requests. Java developers create this interface using JavaServer Pages (JSPs), HTML, and JavaScript. ColdFusion shops use ColdFusion Pages (CFMs), HTML, and perhaps some JavaScript.

The Controller is responsible for directing traffic between and among the Model and View objects. As the View submits information, that information is passed to the Controller, which implements the proper Model object for manipulating or storing the data. The Controller might invoke a new View to provide user feedback on the Model's success or failure to process that information. Likewise, when the View requests information, the request is submitted to the Controller. The Controller calls the necessary Model(s) to get the information and then passes that information to an appropriate View object for display. How‹or perhaps I should say where‹this Controller function is implemented is what differentiates Model-1 and Model-2 implementations of the MVC design.

A full description of Model-1 and Model-2 MVC implementations can be found in Designing Enterprise Applications with the J2EE Platform, Second Edition by Inderjeet Singh, Beth Stearns, Mark Johnson, and the Sun Microsystems Enterprise Team. This book explains that in a Model-1 architecture, application flow is determined by the links embedded in the JSP or CFM pages; whereas in a Model-2 architecture, a servlet (Controller) is placed between the web pages (the View) and the business objects (the Model) to determine program flow.

So now with all that behind us, we can define Struts as follows: Struts is an implementation of the Controller functionality in a Model-2 MVC architecture.

The next logical question to ask is how do you apply these various roles of MVC architecture to the ColdFusion MX environment? And which ­ if any ­ of these architectures is appropriate for your project?

Applications created using JSP or CFM pages have a tendency to embed some of the business logic within the current page. Although it's possible to separate logic from Views, which are later combined using includes, it's not uncommon for developers‹especially during the final hours of development‹to embed small pieces of logic in the View layer. What's more to the point is that the command richness of both JavaServer Pages and ColdFusion MX allows developers to break rules. Because these types of applications are considered non-MVC conforming designs, they do not perform well over heavy loads. Non-MVC applications are perhaps most appropriate for prototypes and small-scale applications.

More Stories By Steve Belt

Steve Belt is a senior software developer for BrowserMedia, LLC, where he develops innovative software solutions for associations and finds new ways to use the Internet to make their lives easier. Before joining BrowserMedia, Steve led the development of several web-enabled tools and services used in the bioinformatics industry. Steve also participates heavily in several Java open-source projects.

Comments (1) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
ColdFusion Developer's Journal News Desk 01/08/06 04:31:33 PM EST

Although earlier versions of ColdFusion supported Java objects and servlets to some degree, ColdFusion MX does so in a big way. This support opens up commercially available libraries to ColdFusion developers that were previously only available to J2EE shops. Moreover, you can now draw from an immense library of free code from within the Java open-source community. This availability greatly enhances the features of your own applications and speeds your ColdFusion-based solutions to market. Use these objects to provide back-end processing or user-interface functionality, or simplify coding CFM pages by supplementing ColdFusion functions and tags with Java TagLibraries.

IoT & Smart Cities Stories
As IoT continues to increase momentum, so does the associated risk. Secure Device Lifecycle Management (DLM) is ranked as one of the most important technology areas of IoT. Driving this trend is the realization that secure support for IoT devices provides companies the ability to deliver high-quality, reliable, secure offerings faster, create new revenue streams, and reduce support costs, all while building a competitive advantage in their markets. In this session, we will use customer use cases...
Bill Schmarzo, author of "Big Data: Understanding How Data Powers Big Business" and "Big Data MBA: Driving Business Strategies with Data Science," is responsible for setting the strategy and defining the Big Data service offerings and capabilities for EMC Global Services Big Data Practice. As the CTO for the Big Data Practice, he is responsible for working with organizations to help them identify where and how to start their big data journeys. He's written several white papers, is an avid blogge...
When talking IoT we often focus on the devices, the sensors, the hardware itself. The new smart appliances, the new smart or self-driving cars (which are amalgamations of many ‘things'). When we are looking at the world of IoT, we should take a step back, look at the big picture. What value are these devices providing. IoT is not about the devices, its about the data consumed and generated. The devices are tools, mechanisms, conduits. This paper discusses the considerations when dealing with the...
Business professionals no longer wonder if they'll migrate to the cloud; it's now a matter of when. The cloud environment has proved to be a major force in transitioning to an agile business model that enables quick decisions and fast implementation that solidify customer relationships. And when the cloud is combined with the power of cognitive computing, it drives innovation and transformation that achieves astounding competitive advantage.
With 10 simultaneous tracks, keynotes, general sessions and targeted breakout classes, @CloudEXPO and DXWorldEXPO are two of the most important technology events of the year. Since its launch over eight years ago, @CloudEXPO and DXWorldEXPO have presented a rock star faculty as well as showcased hundreds of sponsors and exhibitors! In this blog post, we provide 7 tips on how, as part of our world-class faculty, you can deliver one of the most popular sessions at our events. But before reading...
Poor data quality and analytics drive down business value. In fact, Gartner estimated that the average financial impact of poor data quality on organizations is $9.7 million per year. But bad data is much more than a cost center. By eroding trust in information, analytics and the business decisions based on these, it is a serious impediment to digital transformation.
Digital Transformation: Preparing Cloud & IoT Security for the Age of Artificial Intelligence. As automation and artificial intelligence (AI) power solution development and delivery, many businesses need to build backend cloud capabilities. Well-poised organizations, marketing smart devices with AI and BlockChain capabilities prepare to refine compliance and regulatory capabilities in 2018. Volumes of health, financial, technical and privacy data, along with tightening compliance requirements by...
DXWorldEXPO LLC, the producer of the world's most influential technology conferences and trade shows has announced the 22nd International CloudEXPO | DXWorldEXPO "Early Bird Registration" is now open. Register for Full Conference "Gold Pass" ▸ Here (Expo Hall ▸ Here)
@DevOpsSummit at Cloud Expo, taking place November 12-13 in New York City, NY, is co-located with 22nd international CloudEXPO | first international DXWorldEXPO and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The widespread success of cloud computing is driving the DevOps revolution in enterprise IT. Now as never before, development teams must communicate and collaborate in a dynamic, 24/7/365 environment. There is no time t...