CFGroovy

CFGroovy is a Groovy-centric, pluggable scriptlet engine for CFML runtimes.   It allows you to embed any JSR-223 compliant scripting language into your CFML code with transparent passthrough to your normal CFML data structures (url, form, request, session, etc.).  It also provides support arbitrary additional "scopes", assistance with CFML ORM entities, and a few other bits and pieces.

This is not to be confused with CFGroovy 1, which provided similar functionality, but also provided a means to use Hibernate for persistence within CFML applications.  It has been EOLed in favor of engine-provided ORM as of 2010/04/05.

The implementation itself is a single standalone custom tag.  It comes bundled with the Groovy JAR and Mark Mandel's JavaLoader so that it can be used without changing your classpath or restarting your server.  However, if Groovy is already on the classpath, that will be used as-is and the bundled JAR will be ignored.

Installing your own Groovy JAR is the preferred way to use CFGroovy; I only bundle JavaLoader and the Groovy JAR to make it easier for people to give it a test spin.   The classloading voodoo that JavaLoader does can occasionally have strange side effects (not because of JavLoader, mind you, just because classloading is really picky about stuff), and it's generally better to have all your external dependencies in a single location (/WEB-INF/lib) rather than spread around.

Other languages can be pulled in via the 'lang' attribute to the tag.  The JARs implementing those languages MUST be on the classpath – only Groovy will be loaded via JavaLoader.

Within the body of your script, you have access to variables, url, form, request, cgi, session, application, server, and cluster scopes, assuming they exist.  You also have a pageContext variable holding the results of getPageContext().  Here is a simple example using the variables scope:



  variables.people.sort { it.name }

You can also supply arbitrary bindings as attributes to the tag.  For example, if you'd like to access a CFC method's arguments scope, you can do this:



  arguments.myArg = arguments.myArg.tokenize(',').groupBy {
    Integer.parseInt(it) % 4
  }

// arguments.myArg == {'0': [4, 0], '1': [9], '2': [2], '3': [7, 3]}

CFGroovy is targeted at Adobe ColdFusion 8+, Railo 3.1+, and Open BlueDragon 1.0+.  There is no intended support for other engines or versions, though as long as they're JVM based and support custom tags and createObject("java", …) there's a good chance it'll work.

The engine (including JavaLoader) is available from Subversion here:

https://ssl.barneyb.com/svn/barneyb/cfgroovy2/trunk/engine/

The demo "app" is available for viewing here (though I don't have Jython or Quercus installed for the Python and PHP scriptlets):

http://www.barneyb.com/cfgroovy2/

and from Subversion here (the demo includes the engine):

https://ssl.barneyb.com/svn/barneyb/cfgroovy2/trunk/demo/

For historical perspective, CFGroovy was created because CFGroovy 1 (previously just CFGroovy) had morphed from a simple Groovy scriptlet engine into a full-blown Hibernate integration package for CFML.  While doing that it lost much of it's ability to function as a super-lightweight scriptlet engine.  As a result I started back from ground zero and build CFGroovy 2.  As of today (2010/4/5) CFgroovy 1 has been EOLed with CFML ORM as it's replacement.  CFGroovy 2 continues to serve a much needed purpose in CFML applications, both in conjunction with the CFML ORM functionality, and for standalone scriptlets.  Unlike CFGroovy 1, CFGroovy 2 is not designed as a stopgap measure until CFML engines get some piece of missing functionality (native ORM support), but as a complement to the CFML language as a whole.