Search code examples
grailsgsp

Grails - How to execute a javascript method after a template is rendered?


I'm trying to execute a javascript code to initialize certain components in my gsp template. I need the script code to be executed after the template is loaded. The template is loaded from a controller. Any idea how this can be achieved?

Code to render the template within the controler:

render(template: 'myTemplate', model:[user:User])

I'm using formRemote to call the controller

<g:formRemote url="[action:'showMeTemplate', controller: 'User']" name= "formName" update="myTemplateDiv">
</g:formRemote>

Solution

  • Try onSuccess or onComplete events on the formRemote tag.

    See http://grails.org/doc/latest/ref/Tags/formRemote.html