« Rob Burgess to do the Seybold 2003 Keynote | Main | Binary Deployment of ColdFusion Applications »
September 08, 2003
Leveraging Java in Your ColdFusion Applications
There are four basic ways to use Java with ColdFusion:
- CFX tags
- JSP tags
- Using
CFOBJECTorcreateObject()to accesses custom classes in your classpath - Direct embedding (usually using CFScript)
CFX tags have a very straightforward interface. You simply implement a function called processRequest contained in the interface com.allaire.cfx.CustomTag, and work with the Request and Response objects that get passed in. CFX tags are the easiest way to implement ColdFusion tags in Java. The JSP custom tag interface is much more complex and flexible, allowing you to respond to very specific tag parsing events, nest tags, and work with body content. Using the CFOBJECT tag or createObject function is as easy or difficult or as the APIs you are accessing, while the simplest way to work with Java in ColdFusion is probably to embed it directly, typically using CFScript.
How often do you find yourself using Java in your ColdFusion applications? What do you typically use it for, or what have you used it for in the past? Finally, which of the techniques above do you typically use, and why?
Posted by cantrell at September 8, 2003 11:22 AM | References
Comments
I find myself exploring more and more with #3 (using createObject()).
Posted by: Todd at September 8, 2003 12:12 PM
I am using Java in CFML more and more. I started with things than in CF 5 required COM objects or external programs, like image manipulation. Now I am also using it for advanced XML/XSL/DOM stuff and file I/O (including zip files).
I never felt the need to use CFX and I only evaluated a few JSP tags, mainly for testing
The italian CFUG website has a section dedicated to Java/CFML integration:
http://www.cfmentor.com/code/index.cfm?action=ls_script&cat=14
Posted by: Massimo Foti at September 8, 2003 12:16 PM
i use createObject w/cfscript for i18n functions for locales that cf doesn't support, interface with 3rd party apps (like arcIMS via its java connector, inetAddressLocator, etc.) or whenever i need something thats faster or easier in java. daily, i guess.
you can directly embed java in cfscript? can you post some examples?
Posted by: paulH at September 8, 2003 12:22 PM
I find myself using createObject a lot in response to webforum questions, but I hardly ever use Java in our boring production apps. The only production instance is a CFX tag for spell checker.
What is the difference between #3 and #4? By direct embedding do you mean the forName() thing? I've done that once when we needed to upload files on a shared host that had cffile disabled, but would have rather the host enabled cffile and just implemented directory security properly.
Posted by: Sam at September 8, 2003 12:42 PM
reflection's a bear for anything complicated.
Posted by: paulH at September 8, 2003 12:53 PM
I just added the word "custom" to #3 to make it clearer. What I mean is that you don't have to use the CustomTag or the JSP custom tag interfaces to use Java from CF. You can just write any types of objects you want, and as long as they are in your classpath, you can instantiate them using CFOBJECT or createObject. #4 refers to using the JDK directly from ColdFusion (which is essentially using introspection) without writing your own Java files.
Christian
Posted by: Christian Cantrell at September 8, 2003 01:16 PM
I used to do a lot of Java CFX tags, but have more recently dropped that in favor of using createObject in CFSCRIPT. I love the Java support in CFMX, and I feel like I have so much more unhindered access to Java assets in CFMX than I ever have.
Posted by: Michael Buffington at September 8, 2003 02:23 PM
... and I have just bought a new book "Java for ColdFusion Developers" from Eben Hewitt and it seems not bad. :-)
And I am just converting my image tools into Java based solutions. As you know CFX_Image etc. sucks and I think JAI or other opportunities rocks! :)
Posted by: Tarantor at September 8, 2003 03:04 PM
Just like the previous comment, I am using Java to manipulate images and also to convert between file types (pdf, etc).
I use CFScript for this, as I found it to be a lot easier than the other options. I had never used CFX tags in the past because the interface was a little limited.
Posted by: Jade at September 8, 2003 07:17 PM
I guess I use #3 most with some #4. If the Java API is complex or ugly, I just wrap it up in a CFC and expose a more CF-friendly interface.
BTW, I see Daine has spammed your blog too...
Posted by: Sean Corfield at September 9, 2003 02:58 PM
Just like the previous comment, I am using Java to manipulate images and also to convert between file types (pdf, etc).
I use CFScript for this, as I found it to be a lot easier than the other options. I had never used CFX tags in the past because the interface was a little limited.
Posted by: Buy.com at December 10, 2003 07:12 PM
I found these blogs following links on a java image manipulation search. I am trying to find some java manipulation resources to use in CFC.Any links, resources info appreciated. I am not looking for a pricey solution but something open source that I can use.
Thanks
Posted by: rlash at August 16, 2004 11:05 PM
I would like to know, when and why are the best times to use java in a cold fusion page
Posted by: bullcatt at September 9, 2004 02:39 PM