1

I have a site that have URL similar to this:

/mysite/admin/controller/action/id
/mysite/search/controller/action/id
/mysite/user/controller/action/id

I have my URL mapping like this

"/$prefix/$controller/$action?/$id?"{
    constraints {}
}

I am able to get to the controller correctly.

But on the GSP side

<g:link controller="controller">abc</g:link> ==> <a href="/mysite/controller/...">abc</a>

Notice how I lose the prefix between mysite and the controller.

Sudhir N
  • 4,008
  • 1
  • 22
  • 32
Churk
  • 4,556
  • 5
  • 22
  • 37

2 Answers2

3

You can use named url mappings and then pass the prefix as part of the params:

URLMappings:

name prefix: "/$prefix/$controller/$action?/$id?"{
    constraints {}
}

GSP:

<g:link mapping="prefix" params="[prefix:$prefix, controller:...]">abc</g:link>

To use sortableColumn, just put all of the URLMapping parameters in the params property:

<g:sortableColumn property="col" title="title" params="[ prefix: 'prefix', controller:'controller', action:'action']" />
seth.miller
  • 1,988
  • 17
  • 23
0

It works when you hit the URL in browser, because prefix is available in URL. It does not work when you use link tag to create url, because grails does not have information about which prefix should be used for this controller. You will need to provide the value for prefix to link tag.

Try this

<g:link controller="controller" params="[prefix:'admin']">abc</g:link>

in-short - You have to pass those dynamic variables as params if you want link re-writing to consider them. Read more docs here

Sudhir N
  • 4,008
  • 1
  • 22
  • 32
  • I understand that I need to pass the params="[prefix:'admin']", what I am try to say is. It works only for the URL for this translates to /mysite/controller/action/id?prefix=admin, and my prefix is gone in the URL. – Churk Feb 13 '12 at 17:52
  • In that case you will have to change url mappings to explicitly specify the controller name "/admin/$controller/$action?/$id?"(controller:"Admin") "/search/$controller/$action?/$id?"(controller:"Search") – Sudhir N Feb 14 '12 at 03:41
  • Yes, I attempted that, that actually was my first attempt and it still does not retain the prefix. – Churk Feb 14 '12 at 18:08