I have something like this in my website:
<body>
<div id="1">
content1
</div>
<div id="2">
content2
</div>
<g:render template="/layouts/aa1"/>
<g:form name="myForm" action="myaction">
<g:submitButton name="update" value="Update" />
</g:form>
</body>
My aa1 layout is something like this:
<div id="3">
<g:each in="print">
${it.carModel}
</g:each>
</div>
And the controller is:
def updateDiv = {
def max = 20
def offset = 0
if(params=["myForm"]){
def print = Cars.list(max: max, offset: offset + 10)
}
render(template:'aa1', [print: print])
}
What i wanna do is, when i click ‘Update’, g:render is called again and updated with ajax (update only that part), and the values change. Each time is clicked, the next 20 cars are shown. How can i accomplish that? Am i in the right direction?
Grails has a tag
formRemotethat does this for you.Basically, instead of using the regular
formtag, you use aformRemotetag, specifying the controller and action to invoke and the dom element to update with the results.You can also look at the
submitToRemotetag which does something similar.I’ve stubbed out some code below s oset you on the right direction. Its not tested so there might be errors in it
CONTROLLER:
GSP:
TEMPLATE: