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" /> <cfscript> myArray = [ "barney" ]; </cfscript> <!--- thanks Groovy ---> <g:script> variables.myArray.add("heather") </g:script> <!--- thanks Quercus ---> <g:script lang="php"> <?php $variables["myArray"][] = "lindsay"; ?> </g:script> <!--- thanks Jython (and damn your semantic whitespace!) ---> <g:script lang="python"> variables["myArray"].append("emery") </g:script> <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.
it's cool and all, but I don't see in there where i can use vb. So, this sucks.
nice try though.
:-)
Java 7 is supposed to have a Basic implementation included. Not sure how VB-ish it is, but Basic none the less. So it might just be a matter of time. :)
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.
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?
@TJ
My pleasure. Glad you're benefiting; I know I sure have.
@Marc
Yeah, I know you were kidding. But still a good illustration of just how all-encompassing JVM language integration could potentially be. Can you imaging telling client X that their VB.NET application can pretty much just run as part of a CFML application?
jQuery is pretty focused on the DOM and UI stuff, which makes it largely non-applicable for server-side stuff. However, the other bits (like each()) will happily run already. When I build CFRhino years and years ago (pre-jQuery, and pre-JSR 223) I was using a number of Prototype's extensions in my server-side code without issue. The jQuery stuff should be similarly usable. CFRhino never got very far because it was 100% kludge, with no transparent passing of data structures from one side to the other. JS follows very different rules than Java, so there isn't a 1:1 mapping passing stuff from CFML to JS like there is when passing from CFML to Groovy.
At Mentor we do CFML, Groovy, and Java on the server-side. Joshua has done a bit of Python on the side, and Oscar has experimented with a number of languages, but in production code we've not used anything aside from Groovy. Most of the Groovy stuff we've done is CFG1 with Hibernate (on our service tier), but our presentation tier is growing more and more Groovy, and it's all CFG2. Like I said in my post, Groovy seems to compliment CFML development the best of the JSR 223 languages, so it's what we use on a day-to-day basis. It also has each(), collect(), map(), etc. already waiting, which is awesome.
That is cool. Real real cool.
@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.
Cheers,
Marcel
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: https://aptana.lighthouseapp.com/projects/35272-studio/tickets/97 Just thought I'd mention it :)
Actually perhaps CFGroovy 2 should be included within Railo, I just added a ticket to the Railo user voice site: http://railo.uservoice.com/pages/21016-general/suggestions/346953-include-cfgroovy2-or-similar-as-part-of-railo
@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
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.
@Justin
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.
@Marcel,
There's nothing I need to do, you just need to have the right script engine installed in your classpath. CFGroovy2 simply looks up the engine based on the 'lang' attribute, so as long as you have the right engine installed, you can run any language you want.
Sun JVMs bundle Rhino, obviously, so I'm not sure what problems you might run into with version conflicts if you try to supply your own. That goes for any script engine you might choose: you can't really have two different versions running inside the same web app, because they can't both exist on the classpath concurrently. Rhino is just special in that every JVM already has an instance. But that's totally outside the scope of anything CFGroovy can help with, it's purely about Java classloading and all the associated voodoo.
Worst case scenario, you could use something like JarJar to renamespace Rhino so you can install a new version in some other namespace and load it up that way under an alternate language alias.
@Barney
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 :)
[...] B has put together a CF system to allow for embedded PHP, jRuby and [...]