You can use the cfimport tag to import custom tags from a directory as a tag library, or to import a Java Server Page (JSP) tag library. A JSP tag library is a packaged set of tag handlers that conform to the JSP 1.1 tag extension API.
<cfimport taglib = "taglib-location" prefix = "custom" webservice = "URL">
New in ColdFusion MX: This tag is new.
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:
<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 does not work within a cfinclude call. ColdFusion does not throw an error in this situation. To include tags from a JSP tag library, you must put the cfimport tag at the top of every page that is called by the cfinclude tag. (Putting the cfimport tag into an application.cfm file does not propagate the import.) For example, put a statement such as the following in each page that is called by the cfinclude tag:
<cfimport taglib="/WEB-INF/webcomponent" prefix="c">
You cannot use this tag to suppress output from a tag library.
For more information, see the Java Server Page 1.1 specification.
<h3>cfimport example - view only</h3>
<cftry>
<!--- Import the JRun Custom Tag Libraries --->
<cfimport
taglib="jruntags.jar"
prefix="customtag">
<customtag:sql datasrc="#regdatasource#" id="x">
SELECT employee_id, firstname, lastname, email, phone, department
FROM employees
WHERE employee_id < 3
</customtag:sql>
<customtag:param id="x" type="allaire.taglib.querytable"/>
<table>
<customtag:foreach group="#x#">
<tr>
<cfoutput>
<TD>#x.get("employee_id")#</TD>
<TD>#x.get("firstname")#</TD>
<TD>#x.get("lastname")#</TD>
<TD>#x.get("email")#</TD>
<TD>#x.get("phone")#</TD>
<TD>#x.get("department")#</TD>
</cfoutput>
</tr>
</customtag:foreach>
</table>
<cfcatch>
<cfoutput>#CFCATCH.message# - #CFCATCH.DETAIL# </cfoutput>
</cfcatch>
</cftry>
<h3>id= cfimport-jruntags-sql-pos-1-t1</h3>
<table>
<tr>
<td>1</td>
<td>carolynn</td>
<td>peterson</td>
<td>cpeterson</td>
<td>(612) 832-7654</td>
<td>sales</td>
</tr>
<tr>
<td>2</td>
<td>dave</td>
<td> heartsdale</td>
<td>fheartsdale</td>
<td>(612) 832-7201</td>
<td>accounting</td>
</tr>
</table>
ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting
Version 6
Comments are no longer accepted for ColdFusion MX. ColdFusion 8 is the current version.
RSS feed | Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/coldfusion/6/CFML_Reference/Tags-pt158.htm
Comments
sundvor said on Jul 22, 2002 at 7:27 AM : sgilson102 said on Aug 15, 2002 at 2:58 PM : rbils@amkor.com said on Oct 7, 2002 at 10:47 PM : typomatic said on Nov 15, 2002 at 2:41 AM : hlichtin said on Feb 4, 2003 at 12:25 PM : Mark Mongeau said on Oct 24, 2003 at 10:55 AM : mcollins said on Feb 3, 2005 at 8:26 AM :