Saturday, May 1, 2010

So I dig me some grails named URL mappings. They allow you to associate a logical name with a URL mapping, and then to specify that name later when rendering links with the
tag to have it write the URL appropriately. Here is an example...

In UrlMappings.groovy:

name profileMapping: "/profile/show/$alias/$listOd?" {
controller = "profile"
action = "show"
}


In a GSP page:

<g:link mapping="profileMapping" params="${[alias: profile.alias, list: currentList.id]}"/>


This is important, because often the default mapping of /controller/action/id is not the best suited for the task. You might want to specify something more human readable than a numeric ID for usability and SEO, for instance.

Anyway, this is just another reason I really like grails.

No comments:

Post a Comment