Monthly Archives: March 2010

g:truthLink – taglib for optionally rendering a link based on groovy truth

Very often, there are requirements in the UI to render a link only when some conditions are met. You want to disable the link if the item is selected, not in use, etc.

Using just gsp tags, you would do something like this:

<g:if test="${ someCondition }"><g:link action="blah"></g:if>someBodyCode<g:if test="${ someCondition }"></a> </g:if>


<g:if test="${ someCondition }">
    <g:link action="blah"> someBodyCode </g:link>

Neither of these approaches is very elegant since it forces you to either repeat the content block or the conditional block.

With grails tags, we can write our own link taglib that supports passing an optional truth parameter. It looks like this:

   <g:truthLink test="${somecondition}" action="blah"> someBodyCode </g:truthLink>

and the tag library is ridiculously simple:

class TruthLinkTagLib {
	def truthLink = { attrs, body ->
		if( attrs['test'] )
			out << attrs, body )
			out << body()

This keeps things simple and you can pass in any additional parameters you would pass into g:link.

Hope that helps,

The truthlink will set you free…

Hot-pluggable extensions in Grails – adding and changing your application behaviour on the fly

One of the biggest challenges in developing web applications is the ability to alter the behaviour of your program once the application has been deployed.

If you are building a highly extensible application like a content management system or an e-commerce engine, you don’t necessarily want to restart or redeploy every time a change has been made. You also want the ability to define business rules, add custom scripts, and turn functionality on and off.

In this post, I will show you how to externalize application functionality using closures, the Groovy configSlurper and the pluggable behaviour pattern.

Continue reading

Migrating a Spring Application to Grails: Where do I put all my stuff?

As some of you might now, I started a new job with DMC Digital / Dealchecker. One of my first tasks was to migrate a pretty large Spring application ( ~650 beans, 120 domain objects ) into Grails. In the next posts, I will outline some of the lessons learned and share tips and ideas about enabling the Grails stack within large Spring Applications.

One of the more daunting tasks is figuring out where to put all the Spring-related stuff into the Grails application structure. Here is a picture I made to help myself remember where all the bits and pieces fit. ( Think of it as chapter 1 of my upcoming and completely fictitious Head First Spring – Grails Migration book ).

BTW, DMC Digital is still looking for talented Grails developers