Using TagLib to avoid changes due to change in URLMappings
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.