To create a Java CFX tag, create a class that implements the Custom tag interface. This interface contains one method, processRequest, which is passed Request and Response objects that are then used to do the work of the tag.
The example in the following procedure creates a very simple Java CFX tag named cfx_MyHelloColdFusion that writes a text string back to the calling page.
If you receive errors during compilation, check the source code to make sure you entered it correctly. If no errors occur, you successfully wrote your first Java CFX tag.
You call Java CFX tags from within ColdFusion pages by using the name of the CFX tag that is registered on the ColdFusion Administrator CFX Tags page. This name should be the prefix cfx_ followed by the class name (without the .class extension).
Register a Java CFX tag in the ColdFusion Administrator
You can now call the tag from a ColdFusion page.
Call a CFX tag from a ColdFusion page
ColdFusion processes the page and returns a page that displays the text "Hello, Les." If an error is returned instead, check the source code to make sure you entered it correctly.
Delete a CFX tag in the ColdFusion Administrator
Implementing a Java CFX tag requires interaction with the Request and Response objects passed to the processRequest method. In addition, CFX tags that need to work with ColdFusion queries also interface with the Query object. The com.allaire.cfx package, located in the WEB-INF/lib/cfx.jar archive, contains the Request, Response, and Query objects.
For a complete description of these object types, see "ColdFusion Java CFX Reference" in the CFML Reference. For a complete example Java CFX tag that uses Request, Response, and Query objects, see ZipBrowser example.
The Request object is passed to the processRequest method of the CustomTag interface. The following table lists the methods of the Request object for retrieving attributes, including queries, passed to the tag and for reading global tag settings:
Method |
Description |
---|---|
Checks whether the attribute was passed to this tag. |
|
Checks whether the tag contains the debug attribute. |
|
Retrieves the value of the passed attribute. |
|
Retrieves a list of all attributes passed to the tag. |
|
Retrieves the value of the passed attribute as an integer. |
|
Retrieves the query that was passed to this tag, if any. |
|
Retrieves the value of a global custom tag setting. |
For detailed reference information on each of these interfaces, see the CFML Reference.
The Response object is passed to the processRequest method of the CustomTag interface. The following table lists the methods of the Response object for writing output, generating queries, and setting variables within the calling page:
Method |
Description |
---|---|
Outputs text to the calling page. |
|
Sets a variable in the calling page. |
|
Adds a query to the calling page. |
|
Outputs text to the debug stream. |
For detailed reference information on each of these interfaces, see the CFML Reference.
The Query object provides an interface for working with ColdFusion queries. The following table lists the methods of the Query object for retrieving name, row count, and column names and methods for getting and setting data elements:
Method |
Description |
---|---|
Retrieves the name of the query. |
|
Retrieves the number of rows in the query. |
|
Retrieves the index of a query column. |
|
Retrieves the names of the query columns. |
|
Retrieves a data element from the query. |
|
Adds a new row to the query. |
|
Sets a data element within the query. |
For detailed reference information on each of these interfaces, see CFML Reference.