View comments | RSS feed
Contents > CFML Reference > ColdFusion Tags > cfimport PreviousNext

cfimport

You can use the cfimport tag to import either of the following:

Application framework tags

<cfimport 
taglib = "taglib-location"
prefix = "custom">

cfapplication

ColdFusion MX: Added this tag.

Attribute

Req/Opt

Default

Description

taglib

Required

 

Tag library URI. The path must be relative to the web root (and start with /), the current page location, or a directory specified in the Administrator ColdFusion mappings page.

  • A directory in which custom ColdFusion tags are stored. In this case, all the cfm pages in this directory are treated as custom tags in a tag library.
  • A path to a JAR in a web-application; for example, "/WEB-INF/lib/sometags.jar"
  • A path to a tag library descriptor; for example,
    "/sometags.tld"

Note: You must put JSP custom tag libraries in the
/WEB-IN/lib directory. This limitation does not apply to ColdFusion pages.

prefix

Required

 

Prefix by which to access the imported custom CFML tags JSP tags.

If you import a CFML custom tag directory and specify an empty value, "", for this attribute, you can call the custom tags without using a prefix. You must specify and use a prefix for a JSP tag library.

The following example imports the tags from the directory myCustomTags:

<cfimport 
   prefix="mytags" 
   taglib="myCustomTags">

You can import multiple tag libraries using one prefix. If there are duplicate tags in a library, the first one takes precedence.

JSP tags have fixed attributes; however, if the tag supports runtime attribute expressions, most tag libraries support the use of the syntax #expressions#.

To reference a JSP tag in a CFML page, use the syntax <prefix:tagname>. Set the prefix value in the prefix attribute.

To use JSP custom tags in a ColdFusion page, follow these steps:

  1. Put a JSP tag library JAR file (for example, myjsptags.jar) into the ColdFusion server directory wwwroot/WEB-INF/lib. If the tag library has a separate TLD file, put it in the same directory as the JAR file.
  2. At the top of a CFML page, insert code such as the following:
    <cfimport
       prefix="mytags" 
       taglib="/WEB-INF/lib/myjsptags.jar">
    

To reference a JSP tag from a JAR file, use the following syntax:

<cfoutput>
   <mytags:helloTag message="#mymessage#" />
<cfoutput>

The cfimport tag must be on the page that uses the imported tags. For example, if you use a cfimport tag on a page that you include with the cfinclude call, you cannot use the imported tags on the page that has the cfinclude tag. Similarly, if you have a cfimport tag on your Application.cfm page, the imported tags are available on the Application.cfm page only, not on the other pages in the application. ColdFusion does not throw an error in these situations, but the imported tags do not run.

You cannot use the cfimport tag to suppress output from a tag library.

For more information, see the Java Server Page 1.1 specification.

<h3>cfimport example</h3>
<p>This example uses the random JSP tag library that is available from the
Jakarta Taglibs project, at http://jakarta.apache.org/taglibs/

<cfimport taglib="/WEB-INF/lib/taglibs-random.jar" prefix="randomnum">

<randomnum:number id="randPass" range="000000-999999" algorithm="SHA1PRNG" provider="SUN" />
<cfset myPassword = randPass.random>
<cfoutput>
  Your password is #myPassword#<br>
</cfoutput>

Contents > CFML Reference > ColdFusion Tags > cfimport PreviousNext

ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.

Comments


Bryan_Hogan said on Jan 27, 2004 at 10:44 AM :
The taglib attribute value must be static and can not contain a variable.

For example if you have a request.mapping variable setup to contain the name of a mapping that you created in the cf admin. You can not referance this mapping like <cfimport taglib="#request.mapping#" ...>.

Instead you must hard-code the taglib attribute value with your mapping.
rraga said on Apr 21, 2004 at 10:54 AM :
This give a very nice example of using this with a jar, but the example with CF is poor. It only give syntax of making the call, not the actual utilization of the tag with CF.
ednique said on May 12, 2004 at 6:09 AM :
:: CAUTION ::
When using this tag for importing custom tags directory, their will be a difference when using the getbasetagdata() for nested custom tags. Let's say your base template is called page.cfm. When you DON'T specify a prefix the base tag is called "CFPAGE". If you specify a prefix it will be called "CF_PAGE".
halL said on May 12, 2004 at 8:10 AM :
We've submitted a bug report, number 55450, against this behavior:
ColdFusion uses a basetag name of cf_filename for a tag imported without using a cfimport prefix attribute.
ColdFusion uses a basetag name of cffilename for a tag imported using any value as the cfimport prefix attribute.
dfritschy said on Feb 12, 2005 at 2:00 PM :
In addition to what Bryan_hogan said (the taglib attribute must be static) we also encountered the problem that you can not use cfimport within a cfif /cfelse clause. If the template path varies, you REALLY have a problem defining the taglib location.
Chris Peters said on Aug 30, 2006 at 7:40 AM :
<cfimport> is not available for invoking JSP tags in Standard Edition. You must own a copy of Enterprise Edition.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/tags-p62.htm