Developing Hybrid Applications with ColdFusion and Java

Day 1. Session 2. Jason Delmore talks about using Java in ColdFusion and vice versa. There are 3 ways to combine the two areas, made much easier since ColdFusion 6 due to CF running as a J2EE application:
1) CFX tags - You can build custom CFX tags using Java as you can with C+. Each tag must be registered in CF Administrator, and if built incorrectly, these tags can crash the CF server. Personally, I would recommend avoiding Java CFX tags.
2) J2SE & J2EE - Since CF is a Java application, you have the ability to directly create and manipulate Java objects inside your CFM and CFC files. CreateObject() and the CFOBJECT and CFINVOKE tags can all be used to work with Java objects. To create an instance of your Java object, it’s recommended to use CreateObject, and call init() if your class is not a static class. Jason also recommended enclosing the Java instantiation and other work in a CFC or custom tag to make it more accessable for junior developers.
3) JSP tags - You can import and use JSP taglibs in a CFM page just like you would from a JSP page. Using the CFIMPORT tag, you specify a tag prefix, and any tags that start with that prefix are handled by the specified tag library. There are many free / open source taglibs available online, so this is a very powerful feature.
Two other interesting tidbits: All ColdFusion objects implement the Java “serializable” interface, which allows for very fast (and easy) transport of complex data between pages or ColdFusion servers. Also, included JSP files share the same request, session, server, and application scopes. Just use lower-case variable names in JSP so CF can read them.

Tags:

Post a Comment

Your email is never published nor shared. Required fields are marked *

*

*