Reputation: 247
Hey. Imagine i have a something like this:
class Car{
String name
String color
String mark
}
class Motion {
String name
Car carName
}
And i have my view (motion.gsp):
<g:each in="${motion}">
<li>Name: ${it.name}, <br>carName: ${it.carName}, </li>
<br>
</g:each>
What i need to do is, have a link in the 'it.carName' field so, when i click on it, it redirects me to a new page (car.gsp) which will be almost the same as'motion.gsp' but will show the car's properties.
So i checked grails auto-generated gsp files 'show' and saw something like this:
#<td><g:link action="show" id="${countryInstance.id}">${fieldValue(bean: countryInstance, field: "id")}</g:link></td>
#
But i dont think i understand what it does. So my questions are:
a) please explain me how the code betwen ## work.
b) if possible, give me a small hint for the code i need to update to my motion.gsp
Upvotes: 0
Views: 1628
Reputation: 120188
g:link does nothing more than generate a populated <a href=''>
. Check out the documentation here:
basically, in Grails, you have Models, Views, and Controllers. The g:link tag facilitates generating links that make sense according to the Grails MVC convention. The appropriate names parameters of g:link specify which controller, and which action on that controller, to invoke in the link, as well as parameters to pass to the action.
Just try it, its not complicated.
Upvotes: 2