AspAlliance.com LogoASPAlliance: Articles, reviews, and samples for .NET Developers
URL:
http://aspalliance.com/articleViewer.aspx?aId=1523&pId=-1
Creating ColdFusion Application using Fusebox 4.1
page
by Babita Baliarsingha
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 30232/ 53

Introduction

Fusebox is the powerful and standard framework to create the dynamic web sites or web based applications such as ColdFusion or PHP. There are several versions of Fusebox application. Fusebox4.1 is one of them.

Description

A Fusebox 4.1 application consists of Circuits. A circuit corresponds to the directory of the application. There are one or more fuseactions in each circuit. A fuseaction is a request handeller. Fuseaction executes one or more fuses. Fuses are individual CFML pages in ColdFusion.

Fusebox requests are made of the server through a central controller called index.cfm. This is the central channel through which all requests pass and that contains several fuseaction methods.

Listing 1

index.cfm?fuseaction=document.login

Here, central controller is index.cfm and it receives the fuseaction message of document.login.

Document is the circuit name and login is the fuseaction name.

Elements

Fusebox 4.1 newly introduced the XML file rather than the previous version. This version uses XML for two purposes:

·         To provide configuration and initialization information application (i.e fusebox.xml file)

·         To provide configuration and initialization information for individual circuits (i.e circuit.xml file)

The Fusebox application has only one fusebox.xml file. It is located in the root directory of that application.

Let us first explain fusebox.xml.

The Fusebox XML file consists of root element, Fusebox and five prime sub elements.

·         Circuits

·         Classes

·         Parameters

·         Globalfuseactions

·         Plugins

Circuits

The circuits' elements define each circuit in the Fusebox application. The circuits' elements contain one or more circuit elements. Each circuit has an attribute such as alias, path, and parent. The Syntax is:

Listing 2

<circuits>
<circuit alias=”document1” path=”member1” parent=””\>
<circuit alias=”document2” path=”member2” parent=””\>
<circuit alias=”document3” path=”member3” parent=””\>
</circuits>

·         The attribute alias is the name by which the circuit is called.

·         The attribute path defines the path to the directory which contains the circuit's own XML definition files.

·         The attribute parent is the name of the parent circuit, if required.

Classes

The classes element allows map aliases to the component objects. These component objects are ColdFusion component (CFC) files. The classes element consists of one or more class elements.

Here is an example using class elements.

Listing 3

<classes>
<class alias=”Google” class path=”http://www.google.com” type=”webservice” />
<class alias=”Address” class path=”member.com.Address” type=”component” 
    constructor=”init” /> 
</classes>

·         The attribute alias is the name and specifies the class that will access in circuit.xml.

·         The attribute type defines the type of object for the class. The valid objects are:

a) component (if the class is CFC's)

b) java (for Java classes)

c) webservice (for Web services)

d) com (for COM object)

e) corba (for CORBA objects)

·         The attribute class path defines the path to the class. When we use the CFC, the class path is fulldot separated path to the CFC either from the webroot or a custom tag path. When we use java class, the class path is the java class path. For web service, the class path is the url to call the WSDL file for the web service.

·         The attribute constructor specifies the method within the object that defines its constructor. This attribute is optional.

Parameters

The parameter elements are used to set the fusebox application parameter. Each parameter has attributes name and value.

Listing 4

<parameters>
<parameter name="fuseactionVariable" value="fuseaction" />
<parameter name="defaultFuseaction" value="document.login" />
</parameters>

The attribute fuseaction variable is used to set the value that your application will use. So the URL's and Forms can pass the fuseaction.

Listing 5

index.cfm?fuseaction=document.login

Globalfuseactions

The Globalfuseaction has two sub elements.

a) Preprocess

b) Postprocess

In Preprocess, the fuseactions are executed at the beginning of every request. But in post process, the fuseactions are executed at the end of the every request.

Listing 6

<globalfuseaction>
<preprocess>
........................
........................
</preprocess>
<postprocess>
..........................
..........................
</postprocess>
</globalfuseaction>

Plugins

The last element in fusebox.xml is plugins. The plugin element can contain several phase elements which define six possible places where the Fusebox core can be extended.

Listing 7

<plugins>
<phase name=”preProcess”></phase>
<phase name=”preFuseaction”></phase>
<phase name=”postFuseaction”></phase>
<phase name=”postProcess ”></phase>
<phase name=”fuseactionException”></phase>
<phase name=”processError”></phase> 
</plugins>

An individual plugin can be declared inside any phase.

Listing 8

<plugin name="pluginName" template="pluginFile">

This declaration tells Fusebox to execute the plugin file during the lifecycle of Fusebox.

So the structure of Fusebox.xml is:

Listing 9

<fusebox>
<circuits>
.............................
.............................
</circuits>
<classes>
............................
.............................
</classes>
<parameters>
............................
...........................
</parameters>
<globalfuseactions>
..........................
..........................
</globalfuseactions>
<plugins>
........................
........................
</plugins>
</fusebox>

Circuit.xml file

As there is only one fusebox.xml file in Fusebox application. We need the circuital file in each circuit's directory. This is defined as:

Listing 10

<circuit access=”public”>
<prefuseaction>
<do action=”document.hello”>
</prefuseaction>
<fuseaction name=”helloworld”>
<include template=”dsp_helloworld.cfm” />
</fuseaction>
</circuits>

Circuit

The root element of circuit.xml is circuit. Within the circuit there are three sub elements.

a) prefuseaction

b) fuseaction

c) postfuseaction

The circuit has two optional attributes: access and permission. They are used to set default values for the same attributes on the fuseactions within the circuit.

The attribute access may be public, internal and private. If no access attribute is specified, the default value is internal. There is no default value for permissions.

The prefuseaction holds the fuseactions to be executed automatically before the initially called fuseaction is executed. If you have a request of index.cfm?fuseaction=document.helloworld and you have a fuseaction of home.foo within your prefuseaction element, document.home will be executed, followed by document.helloworld. The postfuseaction element automatically executes after the called fuseaction is completed.

Example

How to display the Helloworld using fusebox technology?

Step 1

First off, download the core files from the website of Fusebox. I am going to be working in the folder D:\project\TestDocument accessible via my browser as http://localhost/FB4.

Since this is a web application, we need the web server. I have used the web server named Internet Information services (ISS). In the IIS, create the virtual directory FB4 whose local Path is D:\Project\ TestDocument in the properties.

Step 2

Create a cfm file called as dsp_helloworld.cfm in that folder containing the following code.

Listing 11

<html>
<head>
<title>
Hello World
</title>
</head>
<body>
<h3>Hello World!!</h3>
</body>
</html>

Now we have the display file that will display the message, but we need to do a little more to get the application to work.

Step 3

Create another file called circuit.xml.cfm. This file uses the XML to define the fuseaction within a particular circuit in the application.

Listing 12

<circuit access="public">
<fuseaction name="helloworld">
<include template="dsp_helloworld.cfm" />
</fuseaction>
</circuit>

Step 4

In this step we need to edit the fusebox.xml file to asign an alias to the circuit. The top the fusebox.xml contains the code.

Listing 13

<circuits>
<circuit alias="main" path="" parent="" />
</circuits>

Since we are creating simple application we do not need to worry about the path and parent attributes and change the alias name to document.

Listing 14

<circuits>
<circuit alias="document" path="" parent="" />
</circuits>

Finally, we need to set the value of defaultFuseaction of fusebox.xml to document.helloworld.

Open the browser and run the application via http://localhost/FB4 or http://localhost/FB4/index.cfm?fuseaction=document.helloworld. If all goes well, you should see "Hello World!!"

Figure 1

Conclusion

Finally, I would like to conclude that Fusebox framework is used in ColdFusion or PHP for developing the secure web application because no one can guess which page this is, due to fuseaction.

By Babita Baliarsingh


Product Spotlight
Product Spotlight 

©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-03-29 5:11:20 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search