User Guide
Writing a Java CFX 393
Writing a Java CFX
To create a Java CFX, you create a class that implements the CustomTag 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.
To create a Java CFX:
1 Create a new source file in your editor.
2 Enter your code. The following code shows how t o create a very simple Java CFX
named
SimpleJavaCFX that writes a text string back to the calling page:
import com.allaire.cfx.* ;
public class HelloColdFusion implements CustomTag
{
public void processRequest( Request request, Response response )
throws Exception
{
String strName = request.getAttribute( "NAME" ) ;
response.write( "Hello, " + strName ) ;
}
}
3 Save the file as HelloColdFusion.java in the classes subdirectory.
4 Compile the java source file into a class file using the Java compiler. If you are
using the command-line tools bundled with the JDK, use the following command
line, which you execute from within the
classes directory:
javac -classpath cfx.jar HelloColdFusion.java
Note
The previous command works only if the Java compiler (javac.exe) is in your
path. If it is not in your path, specify the fully qualified path; for example,
c:\jdk12\bin\javac on Windows NT or /usr/java/bin/javac on UNIX.
If you receive errors during compilation, check the source code to make sure you
entered it correctly. If no errors occur, you just successfully wrote your first Java CFX.
As you can see, implementing the basic
CustomTag interface is straightforward. This
is all a Java class must do to be callable from a CFML page.
Processing requests
Implementing a Java CFX requires interaction with the Request and Response
objects passed to the
processRequest method. In addition, CFXs that need to work
with ColdFusion queries also interface with the
Query object. The com.allaire.cfx
package, located in the classes/cfx.jar archive, contains the
Request, Response, and
Query objects.