Using TagLib to avoid changes due to change in URLMappings « Intelligrape Groovy & Grails Blogs

Using TagLib to avoid changes due to change in URLMappings

Posted by

Recently, I used Taglib to centralize the effect of URL mapping related changes of my grails application.

def userPageLink = {attrs, body ->

def user = User.read(attrs.id)

out << g.link(controller: 'user', action: 'show', params: [name: user.name]) {body()}
}

So wherever I need a link to user page, I can use this Taglib instead of g:link.

<hys:userPageLink id="${user.id}">${user.name}</hys:userPageLink>

Advantage:


Whenever I change the URL Mappings, there is no need to update all the g:link in all my gsp files. I would just update my taglib to cater to new URL Mapping.

This entry was posted on February 14th, 2011 at 9:11 pm and is filed under Grails . You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.

Leave a Reply