Using the Application.cfm Template


Application.cfm should be created in the root directory of the application. These functionalities can be built into this template:

  • Specify application name.

  • Enable session, client, and application management to allow you to use shared variables.

  • Set timeouts for the application or any of the sessions.

  • Specify settings to process the page called by Application.cfm.

  • Define the location for storing client variables.

  • Define application-wide settings, such as variables and constants.

  • Specify the creation of error pages.

Application.cfm contains code that's executed on every page of the application. When a request for an application page is received, ColdFusion searches the page directory for Application.cfm. If it's not there, ColdFusion searches the directory tree. If there are several Application.cfm pages in these directories, ColdFusion uses the first page it finds. When Application.cfm is found, its code is included at the beginning of that application page.

Only one Application.cfm page is processed for each request. If a ColdFusion page has a <CFINCLUDE> tag that indicates an additional page, ColdFusion doesn't look for another Application.cfm page when it includes this additional page.

Naming the Application

The <CFAPPLICATION> tag is used to name an application. You can specify this tag in Application.cfm as

 <CFAPPLICATION name="NameExample"> 

You can use unnamed applications when the application or session scope data is to be shared with existing servlets or JSP pages. There cannot be more than one unnamed application on a server.

Enabling Client, Session, and Application Management

The <CFAPPLICATION> tag specifies shared variables, such as client, session, and application. The syntax for the <CFAPPLICATION> tag is

 <CFAPPLICATION="NameExample" CLIENTMANAGEMENT="Yes/No"             SESSIONMANAGEMENT="Yes/No"> 

<CFAPPLICATION> can set timeouts for application and session scope variables, identify the storage methods for client scope variables, and specify not to use cookies on the client browser. The syntax for this is

 CFAPPLICATION="NameExample" CLIENTMANAGEMENT="Yes/No"                SESSIONMANAGEMENT="Yes/No"                SETCLIENTCOOKIES="Yes/No"                SESSIONTIMEOUT="#CreateTimeSpan(days,hours,minutes,seconds)#"                APPLICATIONTIMEOUT="#CreateTimeSpan(days,hours,minutes,seconds)#"                CLIENTSTORAGE="registry/cookie/name"> 

Settings for Processing the Page Called by Application.cfm

The <CFSETTING> tag specifies the page processing attributes that you want to apply to all pages in your application. The syntax for this tag is

 <CFSETTING     ENABLECFOUTPUTONLY="Yes/No"     SHOWDEBUGOUTPUT="Yes/No"       RequestTimeOut = "Value in seconds"> 

The attributes used with <CFSETTING> tag are

  • ENABLECFOUTPUTONLY. When set to Yes, CFSETTING blocks output of all HTML that resides outside CFOUTPUT tags.

  • RequestTimeOut. This is an integer value that represents the number of seconds. It defines the time limit after which the ColdFusion server treats the page as nonresponsive.

  • SHOWDEBUGOUTPUT. Specifies whether to show debugging output. The valid values are Yes and No. The value No means that the debug information is suppressed.

The <CFSETTING> tag can be used on individual or Application.cfm pages. You may use it in a multiapplication environment to override the ColdFusion Administrator settings in one application.

Define the Storage Location for the Client Variables

Client storage space is a part of the <CFAPPLICATION> tag. The CLIENTSTORAGE attribute specifies storage space as

 <CFAPPLICATION="NameExample" CLIENTSTORAGE="data"> 

There are two options for storing client variables: registry and cookies. The client variables can be stored in the database, which can be a native or ODBC data source. The database needs to be created by using the Administrator.

Define Application-Wide Settings

Application.cfm also sets default variables and application-level constants. You can use it to specify these values:

  • A data source

  • A domain name

  • Style settings, such as fonts or colors

  • Other important application-level variables

The <CFINCLUDE> tag enables you to embed references in ColdFusion pages. This tag includes libraries of commonly used code, such as user-defined functions that are required on many pages of the application. The syntax of the <CFINCLUDE> tag is as follows:

 <CFINCLUDE TEMPLATE="template_name"> 

Here, template_name specifies the path to an existing page.

<CFINCLUDE> checks the directory containing the current page. It then searches the directories explicitly mapped in the ColdFusion Administrator for the included file.

Handling Errors

The <CFERROR> tag specifies application-specific error-handling pages for request, validation, or exception errors. You can use this tag to include contact information, application information, or version identifiers in the error message. <CFERROR> also allows you to display all error messages in the application in a consistent manner. Errors and error pages are discussed in detail in Chapter 14, "Handling Errors and Exceptions Using ColdFusion MX."

Example of an Application.cfm Page

This is a sample Application.cfm:

 <!--- Set application name, enable Client and Session variables ---> <CFAPPLICATION name="NameExample"   CLIENTMANAGEMENT="Yes"   CLIENTSTORAGE="ClientData"   SESSIONMANAGEMENT="Yes"> <!--- Set page processing attributes ---> <CFSETTING SHOWDEBUGOUTPUT="No" > <!--- Set custom global error handling pages ---> <CFERROR type="call" TEMPLATE="callerr.cfm" MAILTO="errorhandler@client.com"> <!--- Get an exclusive lock ---> <CFLOCK scope="application variable" type="exclusive" timeout=20> <!--- Do initialization --->  <CFSET Application.ReadOnlyData.Client = "MyData" > <!--- Set a Session variable ---> <CFLOCK timeout="20" SCOPE="Session" TYPE="exclusive"> <!--- Set Application-specific Variables scope variables ---> <CFSET mainpage = "MainPage.cfm"> <CFSET current_page = "#cgi.path_data#?#cgi.query_string#"> <!--- Include a file containing user-defined functions that are called throughout the application ---> <CFINCLUDE template="commonfiles/examplenameudfs.cfm"> 




Macromedia ColdFusion MX. Professional Projects
ColdFusion MX Professional Projects
ISBN: 1592000126
EAN: 2147483647
Year: 2002
Pages: 200

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net