1.0 RC Released!

View the demo app or download the demo and runtime engine.

CF Groovy is a way to leverage the Groovy language from CFML. In the most basic case, it provides a way to use scriptlets in your CFML code. Scriptlets are written in Groovy, but since Groovy is a superset of Java, you may treat them as Java scriplets instead. Scriplets are embedded within <g:script> tags (imported with CFIMPORT). Scriptlets have access to most of the CF data structures you would expect:

  • request - the CF request scope (not the HttpServletRequest)
  • cgi - the CF CGI scope
  • attributes - the combination of the CF form and url scopes, with form taking precedence
  • variable - the CF variables scope from the context the scriptlet is defined
  • pageContext - the result of calling getPageContext(), from which you can get the HttpServletRequest among other things
  • session - the CF session scope, if it's available
  • application - the CF application scope, if it's available
  • server - the CF server scope

By default, scriptlets can access any class on the JVM classpath. For more advanced usage, you can leverage the classloading capabilities of CF Groovy classloading via the <g:setPath> tag. It allows you to add additional directories to search for Groovy classes, so you can write classes in Groovy and leverage them through scriptlets. Those classes are dynamically reloaded just like your scriptlets, so no need to recompile or restart your container all the time like with Java classes.

As well as the core Groovy engine, Hibernate can be enabled via a plugin.  This allows you to use Hibernate to persist Groovy classes.  It operates on CF DSNs, just like you'd expect, and if you use JPA/Hibernate annotations, you don't need a single line of XML.  Check out the demo apps for more details.

Subversion houses both the engine source, and the demo app source (which includes the engine) that shows a little bit of how the engine can be used. In order to run either, you must install the JAR file (groovy-all-X.Y.Z.jar) from the engine directory into your CF classpath (i.e. /WEB-INF/lib). The demo app is available online at http://www.barneyb.com/cfgroovy/, though you'll want the demo source to follow along with what's happening.

For details about Groovy itself, check out groovy.codehaus.org.