Thursday, November 24, 2011

grails dynamic variable in createLink tag

The problem

I was trying to output the value of a variable inside the params attribute of the createLink grails tag, as follows:

<g:createLink action="listSnpsByIglId" params="[iglId:${sampleInstance.iglId}]" />

But that didn't work, with grails failing to evaluate the expression.

The solution

Instead the ${} should be wrapped around the whole expression as follows:

<g:createLink action="listSnpsByIglId" params="${[iglId:sampleInstance.iglId]}" />


References:

Wednesday, November 23, 2011

grails webflow view state events

Some actions can be performed in view state events, such as the following:

onRender {
                    "good"
                }
                onEntry {
                    "enterview"
                }
                onExit {
                    "exitview"
                }




Reference:
http://jira.grails.org/browse/GRAILS-3997

Tuesday, November 22, 2011

grails No such property: errors for command objects

The problem

When attempting to add a custom error message to a command object (non-domain object), I was trying to do this in the following way:

commandObject.errors.reject(null, "Some error msg")

However, when I go to execute the application, I received the following error:

No such property: errors
 It turns out, that the errors property of a command object is not always created.

The Solution

To have grails automatically create the errors object, the command objects must be annotated as "@Validateable"

and in the Config.groovy file add the following line:


grails.validateable.packages=['package.name.containing.command.object']



References: 

http://grails.1312388.n4.nabble.com/Possible-problem-with-Controller-Commands-and-errors-td2257062.html

http://www.grails.org/doc/1.3.7/guide/7.%20Validation.html#7.5%20Validation%20Non%20Domain%20and%20Command%20Object%20Classes

Monday, November 21, 2011

Grails subflows and LazyInitializationException no session bound

When passing objects between the parent flow and subflow I would use the 'conversation' scope. However, any domain objects loaded from the database during the subflow, would later have it's hibernate session dettached when reused in the parent flow.

To workaround this problem, I've reloaded the objects using their ID values in the parent flow to ensure they are associated with a hibernate session


Reference: http://jira.grails.org/browse/GRAILS-2518

Tuesday, September 13, 2011

mvn eclipse:eclipse Request to merge when 'filtering' is not identical

To setup the eclipse IDE environment for a Maven project, I would typically use the following command:

mvn eclipse:eclipse

However, I received the following error:


[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Request to merge when 'filtering' is not identical. Original=resource src/main/resources: output=target/classes, include=[atlassian-plugin.xml], exclude=[**/*.java], test=false, filtering=true, merging with=resource src/main/resources: output=target/classes, include=[], exclude=[atlassian-plugin.xml|**/*.java], test=false, filtering=false
[INFO] ------------------------------------------------------------------------

It turns out there's bug with the latest version of the eclipse plugin for maven.
The workaround was to use:

mvn org.apache.maven.plugins:maven-eclipse-plugin:2.6:eclipse
References:
http://forums.atlassian.com/thread.jspa?threadID=34952

Wednesday, September 7, 2011

IE likes to cache ajax responses

To disable caching of ajax responses in IE when using jQuery use the following:

$.ajax({
  url: "./chat.php?type=json",
  cache: false,
  dataType: "json",
  success: function(data) {
    // Go do this, go do that…
}});


References:

http://i.justrealized.com/2008/jquerys-getjson-failing-randomly-in-internet-explorer

Sunday, August 7, 2011

grails detecting dependency conflicts

To find out what kind of dependency conflicts you might have in your grails application execute the following:


grails dependency-report

A conflict resulted when I had different versions of the slf4j api

Refernece: http://www.grails.org/doc/latest/ref/Command%20Line/dependency-report.html