Writing a Java CFX tag

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.

To create a Java CFX tag:

  1. Create a new source file in your editor with the following code:
    import com.allaire.cfx.* ;
    
    public class MyHelloColdFusion implements CustomTag {
       public void processRequest( Request request, Response response )
    		throws Exception {
    		String strName = request.getAttribute( "NAME" ) ;
    		response.write( "Hello, " + strName ) ;
       }
    }
    
  2. Save the file as MyHelloColdFusion.java in the WEB_INF/classes directory.
  3. 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 cf_root\WEB-INF\lib\cfx.jar MyHelloColdFusion.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:\jdk1.3.1_01\bin\javac on Windows 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 successfully wrote your first Java CFX tag. For information on using your new tag in a ColdFusion page, see Calling the CFX tag from a ColdFusion page.

This section describes the following topics:


View comments in LiveDocs