createLink

Purpose

Creates a link that can be used where necessary (for example in an href, javascript, ajax call etc.)

Examples

Example controller for an application called "shop":

class BookController {
     def defaultAction="list"
     def list = { [ books: Book.list( params ) ] }
     def show = { [ book : Book.get( params['id'] ) ] }
}

Example usages for above controller:

<g:createLink action="show" id="1" /> == /shop/book/show/1
<g:createLink action="show" params="[foo: 'bar', boo: 'far']"/> == /shop/book/show?foo=bar&boo=far
<g:createLink controller="book" /> == /shop/book
<g:createLink controller="book" action="list" /> == /shop/book/list
<g:createLink url="[action:'list',controller:'book']" /> == /shop/book/list
<g:createLink controller="book" absolute="true"/> == http://portal.mygreatsite.com/book
<g:createLink controller="book" base="http://admin.mygreatsite.com"/> == http://admin.mygreatsite.com/book

Example as a method call in GSP:

<a href="${createLink(action:'list')}">my link</a>

results in:

<a href="/shop/book/list">my link</a>

Description

Attributes

Source

Show Source