sinsanarya
sinsanarya

Reputation: 73

How to pass g:textfiled value from GSP to controller in grails as part of params

I am trying to pass the value of a g:textfield to controller on click of a link.but i get null in controller . Below is the code:

GSP code:

<label class="col-md-2">Profile Name :</label>
<g:textField type="text" name="searchbox"  class="form-control" />
<g:link action="profileSearch" id="searchlnk1" params="[searchboxval:"${searchbox}"]">search</g:link>

when i access the value of serachbox in controller, i get null. Can anyone help?

Upvotes: 0

Views: 2326

Answers (1)

Ian Roberts
Ian Roberts

Reputation: 122374

params="[searchboxval:"${searchbox}"]"

will not pull the value from the form field - GString expressions like ${searchbox} are evaluated on the server side while rendering the form, not on the browser after the form has been filled in.

You need to use a proper form rather than a link, more like:

<g:form action="profileSearch" id="searchlnk1">
  <label class="col-md-2">Profile Name :</label>
  <g:textField type="text" name="searchboxval"  class="form-control" />
  <g:submitButton value="search"/>
</g:form>

Upvotes: 1

Related Questions