I am trying to load a value into a field on a view from the action on a controller. How do I reference the specific field I want to load? In .NET it would be something like: in the button click event, this.txtName.Text = “John”. I don’t understand how to do that from a controller and specifically how to reference the view field. I have tried using the params object but it is coming null. I know I am getting to the action based on println statements that I have used.
Here are the relevant code snippets:
from the view:
<td valign="top" class="value ${hasErrors(bean: planetInstance, field: 'name', 'errors')}">
<g:textField name="name" value="${planetInstance?.name}"/>
</td>
<td class="load">
<g:actionSubmit value="Load" action="nameLoad"/>
</td>
from the controller:
def nameLoad = {
// I want to reference and load the "name" textField from the view
}
Any help would be appreciated.
I cannot tell from your code, but you may have forgotten to map the variable
namein your controller actionnameLoad:With the way the code above is set up Grails will assume there is a view called
nameLoadin the folderYourController. So the URL will be something like:http://localhost:8080/yourapp/yourcontroller/nameloadIn that view you will access
namelike this:${name}Which could be used in any number of tags, like the
<g:select>tag for instance: