Adobe
Products
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
Student and Teacher Editions
More products
Solutions
Creative tools for business
Digital marketing
Digital media
Education
Financial services
Government
Web Experience Management
More solutions
Learning Help Downloads Company
Buy
Home use for personal and home office
Education for students, educators, and staff
Business for small and medium businesses
Licensing programs for businesses, schools, and government
Special offers
Search
 
Info Sign in
Welcome,
My cart
My orders My Adobe
My Adobe
My orders
My information
My preferences
My products and services
Sign out
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out My orders My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Review and Checkout
Adobe Developer Connection / ColdFusion Developer Center /

Building ColdFusion applications using Java

by Vinu Kumar

Vinu Kumar
  • Adobe

Created

26 July 2010

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
CFC ColdFusion ColdFusion Builder 2 JBoss

Requirements

Prerequisite knowledge

This article assumes that you have a basic knowledge of programming in Java and of the JEE architecture.

User level

Intermediate

Required products

  • ColdFusion (Download trial)
  • ColdFusion Builder 2 (Download trial)

Sample files

  • travelnetDemo.zip (252 KB)

Additional Requirements

JBoss Portal + JBoss Application Server (AS)

  • JBoss Portal
  • JBoss Application Server

In this article, you will learn about deploying ColdFusion in JBoss and about developing ColdFusion applications with Java. The sample application, a travel website, demonstrates how to rewrite your JSP to CFML pages and access Java code from your CFML pages. This article also shows you how to write portlets for the JBoss portal and embed the sample application in the portal.

A ColdFusion application can have CFML pages, ColdFusion components (CFCs), JSPs, and servlets. A CFC is a collection of code and resembles classes in Java. Some of the scenarios of interoperability include the following:

  • You can use existing Java APIs or any other third-party Java APIs within CFML code.
  • You can rewrite complex JSP code to simple CFML code.
  • You can add new CFML on top of existing servlets and JSPs.

Deploying ColdFusion in JBoss

  1. Download ColdFusion using the links in the Requirements section. Install ColdFusion and choose the EAR file option in the installer.
Select the EAR option in the installer
Figure 1. Select the EAR option in the installer
  1. For the TravelNet sample application to work with your installation, use the default context root, cfusion, and the admin password admin. Complete the installation process.
  2. Once the installation is complete, set up the JBoss Portal/JBoss ActionScript if you have not already done so. Go to the directory where the ColdFusion EAR file was generated and expand cfusion.ear and cfusion.war files.
  3. Deploy them to JBoss. Name the directories cfusion.ear and cfusion.war.
  4. Copy the expanded EAR file to {JBOSS.HOME}/servers/default/ and start JBoss ({JBOSS.HOME}/bin/run.sh).
  5. Browse to http://localhost:8080/cfusion/CFIDE/administrator to configure the admin.
  6. Enable the J2EE session variable in admin by going to Memory Variables > Use J2EE session variables.
Setting the memory option in ColdFusion administrator
Figure 2. Setting the memory option in ColdFusion administrator

Now you are ready to try the samples and explore some of other Java features of ColdFusion.

Deploying the TravelNet sample application

To deploy the sample application, use the following steps.

  1. Download the sample file linked in the Requirements section.
  2. Expand the TravelNet demo archive. There is an ANT build script available under the travelnet directory, which will help you configure the example. Follow the instructions in the readme.txt to set up the application. The demo is set up based on an HSQL database available with JBoss. Refer to the readme.txt to enable the database.
  3. Browse to http://localhost:8080/cfusion/travelnet to run the demo application.
Screen shot of the TravelNet application
Figure 3. Screen shot of the TravelNet application

Analyzing the application

TravelNet is a sample application shipped with the JRun J2EE server. In the demo application, the JSP pages are simply modified to CFML pages and also made to interact with the Java classes. In addition, CFML can also forward calls to a JSP, as follows:

<cfscript> getPageContext().include("forward.jsp"); </cfscript>

The original JSPs are part of the sample application. The next section will cover how you can rewrite each JSP in CFML.

In home.cfm, you can use the cfquery tag to get the list of activities, as follows:

<cfquery datasource="compass" name="compass"> SELECT trip_id, name, teaser, price FROM trip </cfquery> <cfoutput query="compass"> <tr> <td class="contentBG"><a href="tripdetail.cfm?tripId=#trip_id#">#name# </a></td> <td class="contentBG">#teaser#</td> <td class="contentBG">#DollarFormat(price)#</td> </tr> </cfoutput>

As you can see in the above code, the NumberFormat function is replaced directly with the DollarFormat function. ColdFusion provides many built-in functions, which makes the life of a developer easy. Notice that the JSP include directive is replaced with the cfinclude tag. Also, you can pass parameters through the URL and through the target CFML page in the URL scope, as demonstrated in reservation.cfm:

<cfinput type="hidden" name="tripId" value="#URL.TripID#">

In this script you can see that the form element is replaced with the CFFORM tag. The file, reservationaction.cfm, shows how variables are passed from one page to another in form scope. For instance, the variable #form.tripId# retrieves the tripId from the form scope. In this script, the Java class Reservation is invoked to complete the reservation.

resObj = createObject("java","compass.Reservation"); id = resObj.reserve(#form.tripId#, #form.firstName#, #form.lastName#,#form.ccType#, #form.ccNumber#,#form.ccExpiration#);

The Reservation object returns the reservation ID to the CFML page, which then displays within the CFML page.

Writing portlets using ColdFusion

Now that you have seen how you can use CFML within your pages to replace complex JSPs and also how CFML interacts with Java, this section shows you how to create a portlet for the JBoss portal using ColdFusion. There is a sample CFC available in the example archive called Hello.cfc. The EAR installation copies this file to {JBOSS.HOME}/servers/default/deploy/cfusion.ear/cfusion.war/portlets when deployed using the ANT script. This file extends CFIDE.portlets.ColdFusionPortlet and also implements the functions doView and doHelp. The following script shows an example of integrating the TravelNet application in a portlet.

public void function doView(renderRequest,renderResponse) { writeOutput("Welcome to Travel net "); writeOutput('<a href="/cfusion/travel/index.cfm">TravelNet</a>'); compass = new Query(); compass.setSQL('SELECT trip_id, name, teaser, price FROM trip'); compass.setDatasource('compass'); out = compass.execute(); metaInfo = out.getPrefix(); result = out.getResult(); writeOutput('<table width="800" cellspacing="3" cellpadding="8">'); for ( index = 1 ; index LTE metaInfo.RecordCount ; index = (index + 1)){ WriteOutput( '<tr> <td ><a href="/cfusion/travelnet/tripdetail.cfm?tripId=' & result["trip_id"][index] & '">' & result["name"][index] & '</a></td>' & '<td>' & result["teaser"][index] & '</td>'& '<td>' & DollarFormat(result["price"][index]) & '</td>' & '</tr>' ); } }

As you can see in the code snippet above, the CFC queries the compass data source and displays the query results in a table. The code also uses the script support for query introduced in ColdFusion 9.

Integrating to the JBoss portal

Use the following steps to integrate the portlet to the JBoss portal.

  1. Open portlet.xml available at {JBOSS.HOME}/server/default/deploy/cfusion.ear/cfusion.war/WEB-INF/ and update it with the CFC information.
  2. Remove the comment and update the syntax as follows:
<portlet-class>coldfusion.portlet.ColdFusionPortlet</portlet-class> <init-param> <name>cfcName</name> <value>portlets.Hello</value> </init-param>
  1. Start JBoss server and browse to http://localhost:8080/portal.
  2. Log on with the credentials: admin/admin.
  3. Click the Admin option in the upper-right corner and select the Portlet Definition tab.
  4. The "Hello Portlet" appears. Create an instance of the portlet by clicking Create Instance under Actions.
  5. Specify the instance name and instance display name.
  6. Click the Portal Objects tab and create a new portal page.
  7. Select page Layout from Actions.
  8. Select the portlet instance you created before and add it to the required region (Center or left).
  9. Go to the Portal Objects tab and make the new portlet the default portlet.
  10. Click the portal link in the top-right corner to view the newly created portlet.
The portal page.
Figure 4. The portal page.

As you can see, writing a dynamic portal is much easier and simpler with ColdFusion 9. The cfscript tag enhancements introduced in ColdFusion 9 will also help Java developers write code faster and help them take advantage of using existing Java applications.

Where to go from here

ColdFusion allows clear separation of business logic and user interface. It is possible to spend less time and enhance the look of a web application through using ColdFusion. ColdFusion also supports integration with hibernate and allows the creation of Ajax-based web UIs. In summary, it’s easy to convert a Java application to a ColdFusion application in a short time, which gives you the capabilities of both Java and ColdFusion on one server.

Refer to the ColdFusion Developer’s Guide to learn about writing ColdFusion applications and portlets for other portal servers.

Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License

More Like This

  • Object-oriented programming: Using inheritance wisely
  • Easy rich Internet applications with ColdFusion 8
  • What's new in ColdFusion Builder 2
  • Building your first data management application with ColdFusion and Flex
  • What's new in ColdFusion Builder 2.0.1
  • Getting started with RESTful web services in ColdFusion
  • Getting started with ColdFusion Builder 2
  • What's new in ColdFusion 10
  • Using Axis2 web services with ColdFusion 10

Tutorials & Samples

Tutorials

  • Using Axis2 web services with ColdFusion 10
  • Serving HTML5 videos with ColdFusion 10
  • HTML5 WebSockets and ColdFusion -- Part 2

Samples

ColdFusion Blogs

More
07/06/2012 Adobe ColdFusion 10 on CIO.com
06/22/2012 Elishia Dvorak Joins as ColdFusion Solution Consultant and Product Evangelist
06/19/2012 Outstanding contributions to the ColdFusion 10 and ColdFusion Builder 2.0.1 pre-release
06/18/2012 CF html to pdf service - consume from node.js using rest api

ColdFusion Cookbooks

More
04/01/2012 Send multiple mails with the adresses from database
07/27/2011 Passing a list with with STRING values
05/27/2011 AUTOMATED SANITIZED Resultset with ColdFusion
03/16/2011 Using Metadata To Add Static Variables to ColdFusion Components

Products

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • Mobile Apps
  • Photoshop
  • Touch Apps
  • Student and Teacher Editions

Solutions

  • Digital marketing
  • Digital media
  • Web Experience Management

Industries

  • Education
  • Financial services
  • Government

Help

  • Product help centers
  • Orders and returns
  • Downloading and installing
  • My Adobe

Learning

  • Adobe Developer Connection
  • Adobe TV
  • Training and certification
  • Forums
  • Design Center

Ways to buy

  • For personal and home office
  • For students, educators, and staff
  • For small and medium businesses
  • For businesses, schools, and government
  • Special offers

Downloads

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy Policy and Cookies (Updated)

Ad Choices

Reviewed by TRUSTe: site privacy statement