I want to create g:link
which will redirect to
www.xyz.com/controller/action/title_of_question
instead
www.xyz.co">
Search code examplesgrailsgrails-2.0grails-controllerGrails: can we pass string as id in g:link? Or any other way?
Scenario:
I want to create g:link
which will redirect to
www.xyz.com/controller/action/title_of_question
instead
www.xyz.com/controller/action/id_of_question
I know that later one can be created easily configuring id
param of the g:link
.
Please note that title_of_question
is String
separated with hyphen (-)
Can anybody suggest me how to achieve it?
Solution
Short answer: yes, we can :)
If you have no rule in UrlMappings.groovy
which defines id
as Long
or Integer
you can create links with String
identifier like below:
<g:link controller="controllerName" action="show" id="someName">Link!</g:link>
And define controllers action with identifier as String
:
def show(String id) {
...
}