Friday, June 29, 2012

Netflix and Grails...

Good to see they've let this out to share with others!

Friday, June 22, 2012

Ran into a rather nasty Grails 2.0.4 bug the other day...

After deploying my first real production Grails 2.x application, which uses 2 plugins I also wrote, I got the lovely error trying to start the war file in Tomcat 6:


SEVERE: Exception sending context initialized event to listener instance of class org.codehaus.groovy.grails.web.context.GrailsContextLoaderListener org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pluginManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: Lgrails/test/mixin/services/ServiceUnitTestMixin; at java.lang.Thread.run(Thread.java:722) Caused by: java.lang.NoClassDefFoundError: Lgrails/test/mixin/services/ServiceUnitTestMixin; at java.lang.Class.privateGetDeclaredFields(Class.java:2308) at java.lang.Class.getDeclaredField(Class.java:1897) ... 1 more Caused by: java.lang.ClassNotFoundException: grails.test.mixin.services.ServiceUnitTestMixin ... 3 more There is some magic combination of plugins I think is causing this. It originates from one of my plugins, but I can't find anything wrong with it, other than Grails did not package the class (It shouldn't be looking for it AFAIK). So here is my workaround solution, which is working for now (Add to BuildConfig.groovy): grails.war.resources = { stagingDir, args -> // Manually copy the grails-plugin-testing-2.0.4.jar into war due to bug in Grails 2.0.4 // For some reason grails is making the war depend on this jar from the grails distro copy(file: "lib/grails-plugin-testing-2.0.4.jar", tofile: "${stagingDir}/WEB-INF/lib/grails-plugin-testing-2.0.4.jar") } You can find this in your Grails 2.x distro, under the dist folder. I currently can't re-create it from a scratch project, it happens when I add more complex things to the mix like a maven dependency to another grails plugin coming from my artifactory server.

Wednesday, June 6, 2012

Auto nested property extraction...

I ran into the need for a Grails supported select box with 'optgroup'. I was suprised to find out Grails didn't support this, but I did find a JIRA ticket where a guy added the code but it appears it was forgotten and never included. Here's the link with the code: http://jira.grails.org/browse/GRAILS-3961 However I found the example:


<g:selectWithOptGroup name = "song.id" 
                      from = "${Song.list()}" 
                      optionKey = "id" 
                      optionValue = "songName" 
                      groupBy = "album" />

groupBy doesn't support a tested property I'd expect. For example, say album is a parent 
property domain class, and you really want it to group by the parent's property of 'album.name'.
It will blow up when you do this. So I've modified this bit of code, learning from the Groovy class 'Eval'.

I added this around line 40 of the MyAppTagLib.groovy file:

 if (groupBy instanceof String && groupBy.indexOf(".")) {

                groupKey = Eval.x(el,"x."+groupBy)
 }
This will expand a dot notated nested property to give you the correct string value to sort on. Hopefully this will be merged in the Grails core soon, it seems like people expect this sort of thing these days.