Adobe
製品
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
その他の製品一覧
ソリューション
デジタルマーケティング
デジタルメディア
教育
金融機関
Web Experience Management
その他のソリューション
ラーニング サポート ダウンロード 会社情報
ご購入
アドビストア 安心のサポート& サービス
アカデミックストア 学生、教職員、個人向け
アドビライセンスストア 中小企業向け
ボリュームライセンスについて 企業、教育機関、官公庁向け
販売パートナー
キャンペーン情報
検索
 
情報 サインイン
ようこそ、 さん カート 注文状況 マイアカウント
マイアカウント
注文状況
アカウント情報の変更
コミュニケーションの設定を変更
サインアウト
サインインの目的 お客様のアカウントや体験版ダウンロード、製品の拡張機能、コミュニティエリアへのアクセスなどを管理するため
Adobe
製品 セクション ご購入   検索  
ソリューション 会社情報
サポート ラーニング
サインイン サインアウト 注文状況 マイアカウント
先行予約の提供開始予定日Date. 商品が発送されるまで、クレジットカードには課金されません。提供開始の予定日は変更される場合があります。 先行予約の提供開始予定日Date. ダウンロードの準備が整うまで、クレジットカードには課金されません。提供開始の予定日は変更される場合があります。
個数:
ご購入には学生・教職員個人版の購入資格の確認が必要です。
小計
カートの中身を見る
Adobe Developer Connection / ColdFusionデベロッパーセンター /

Building ColdFusion applications using Java

著者 Vinu Kumar

Vinu Kumar
  • Adobe

Created

26 July 2010

ページ ツール

Facebookでシェア
Twitterでツイート
LinkedInでシェア
ブックマーク
印刷

タグ

必要条件

この記事に必要な予備知識

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

ユーザーレベル

中級

必要な製品

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

サンプルファイル

  • 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

  • Building your first data management application with ColdFusion and Flex
  • Object-oriented programming: Using inheritance wisely
  • ColdFusion 8で作成する初めてのリッチインターネットアプリケーション
  • ColdFusion Builder 2の新機能
  • Getting started with ColdFusion Builder 2
  • What's new in ColdFusion 10
  • What's new in ColdFusion Builder 2.0.1

製品

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • モバイルアプリ
  • Photoshop
  • Touch Apps

ソリューション

  • デジタルマーケティング
  • コンテンツオーサリング
  • Web Experience Management

業種別ソリューション

  • 教育
  • 金融機関

サポート

  • ヘルプ&サポート
  • 注文と返品
  • ダウンロードに関するヘルプ
  • ユーザー登録に関するヘルプ

ラーニング

  • ADC: Adobe Developer Center
  • Adobe TV
  • Design Magazine
  • Photoshop Magazine
  • Focus In

ご購入方法

  • アドビストア
  • アカデミックストア
  • アドビライセンスストア
  • ボリュームライセンスについて
  • 販売パートナー
  • キャンペーン情報

ダウンロード

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

会社情報

  • プレスルーム
  • パートナープログラム
  • 企業の社会的責任(英語)
  • 採用情報
  • 投資家の皆様へ(英語)
  • イベント&セミナー
  • Legal(英語)
  • セキュリティ
  • お問い合わせ
国・地域および言語の選択 日本(変更)
国・地域および言語の選択 閉じる

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.

利用条件 | プライバシーポリシーとCookie (更新)

Reviewed by TRUSTe: site privacy statement