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]}" />


Wednesday, November 23, 2011

grails webflow view state events

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

onRender {
                onEntry {
                onExit {


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:



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