Just in case you didn't come to my talk on leveraging Groovy in your CFML applications at CFUnited, I wanted to share this simple CFM page I demoed:

<cfimport prefix="g" taglib="cfgroovy2" />
  myArray = [
<!--- thanks Groovy --->
<!--- thanks Quercus --->
<g:script lang="php">
    $variables["myArray"][] = "lindsay";
<!--- thanks Jython (and damn your semantic whitespace!) --->
<g:script lang="python">
<cfdump var="#myArray#" label="myArray" />

Yes, that's building a single CFML array (named 'myArray') using CFSCRIPT, Groovy, PHP, and Python.

CFGroovy2 is not a way to plug Groovy code into your CFML; it's a way to plug an arbitrary JSR-223 scripting language into your CFML.  I happen to focus on Groovy because I feel that language best compliments CFML/Java development, but any language that supports the JSR-223 scripting specification (for embeddeding scripting languages into the JVM) will happily run via the <g:script> tag.

15 responses to “CFYourFavoriteJVMLanguage”

  1. marc esher

    it's cool and all, but I don't see in there where i can use vb. So, this sucks.

    nice try though.


  2. TJ Downes

    Hey Barney,

    The fact that you are allowing CF developers who have an interest in expanding their knowledge with other languages to have an easy entry point kicks ass. You deserve a Nobel Peace Price (hey if Obama got one, you deserve one too). Thanks to your efforts, I am quickly gaining an appreciation for Groovy that might have taken me a bit longer to dive into.

  3. marc esher

    That's funny barney… I was, of course, just kidding!

    I was thinking about this on my way home from work: with CFG2, you have single-handedly brought server-side javascript to us CF Devs. You will sit at the right hand of the father for this!

    You know what would be toot sweet: if i could somehow write server-side code with parts of jquery. Specifically, I really like map() and each(). I love the list comprehensions in scala, and It'd be awesome to use that style of programming in my CF Code.

    Have your guys at Mentor been using any other jsr-223 languages with CFG2, or are you sticking with the Groovy?

  4. John Allen

    That is cool. Real real cool.

  5. Marcel

    @Barney @marc esher

    John Resig's env.js library adds DOM into Rhino so that jQuery can run on it. I would love to see it included as part of CF perhaps a CFJS standard where instead of Application.cfc I could have a pure javascript Application.cfjs loading jQuery and reusing code on client and server.

    I'd be so happy I'd no doubt shed a tear or two if Railo implemented such a feature or I could figure out how to hack it together using your code examples Barney.


    PS. I logged tickets for such things in the Railo user voice page and on Aptana's lighthouse to see if they will consider supporting cfml as well: Just thought I'd mention it :)

  6. Marcel

    Actually perhaps CFGroovy 2 should be included within Railo, I just added a ticket to the Railo user voice site:

  7. Justin Carter

    @marc, @Marcel: I've tried jQuery and enj.js in Rhino and CFRhino (almost 12 months ago now I think) but wasn't too successful in using it the way I wanted. On the command line it seemed to work well enough, but inside a Rhino context from a CFML page I wasn't able to get it to load the DOM and load the various .js files to do the processing I wanted, even if I tried to mush it all into a single file.

    For now I'm just sticking to processing some stuff on the client using jQuery and sending it back to the server via Ajax :P

  8. Justin Carter

    Of course, that was meant to be env.js not enj.js :)

    And as yet I haven't tried CFG2, but perhaps it would work a bit better than CFRhino did.

  9. Marcel

    It all depends on being able to use a more recent version of JavaScript, ideally to be most useful we would want JavaScript 1.7 with e4x support like Rhino, if Barney can sort that out in CFGroovy2.1 so we could choose a JavaScript version then I think it would do the job fantastically, till then I will continue trying to hack into Rhino to bend it to my will :)

    I have it loading env.js fine and can see the data and I *think* I have it loading a page, but I just don't know much about getting anything else happening, like getting the html page back again afterwards! That will be easier once I play around with adding jQuery into the mix I am hoping.

  10. Marcel

    Thanks for the response, I appreciate what you have done with CFGroovy, it works really well and would love to try what you have suggested, but unfortunately don't know enough about Java yet. I'll keep playing with it and see how far I get. I'll look up JarJar and see where that gets me :)

  11. JavaScript Magazine Blog for JSMag » Blog Archive » JavaScript inside ColdFusion – CFJS

    [...] B has put together a CF system to allow for embedded PHP, jRuby and [...]