0

I have inputtext filed in my gsp llike this :

<tr class="context">
    <td width="5%" ><a class="addButton" href="#" style="display:none;"  >+</a></td>
    <td width="60%"><input type="text" name="iwd0_description" value="" id="iwd0_description" /></td>                   
    <td width="10%"><input type="text" name="iwd0_tax" value="" id="iwd0_tax" /></td>
    <td width="10%"><input type="text" name="iwd0_discount" value="" id="iwd0_discount" /></td>
    <td width="10%"><input type="null" name="iwd0_total" value="0" required="" id="iwd0_total" /></td>
    <td width="5%" ><a class="deleteButton" href="#"  style="display:none;" >-</a></td>
</tr>

<tr class="context">
    <td width="5%" ><a class="addButton" href="#"     style="display:none;"  >+</a></td>
    <td width="60%"><input type="text" name="iwd1_description" value="" id="iwd1_description" /></td>                   
    <td width="10%"><input type="text" name="iwd1_tax" value="" id="iwd1_tax" /></td>
    <td width="10%"><input type="text" name="iwd1_discount" value="" id="iwd1_discount" /></td>
    <td width="10%"><input type="null" name="iwd1_total" value="0" required="" id="iwd1_total" /></td>
    <td width="5%" ><a class="deleteButton" href="#"  style="display:none;" >-</a></td> 
</tr>

How can I access to input value in my controller?

nickdos
  • 8,348
  • 5
  • 30
  • 47
user2985824
  • 65
  • 2
  • 5

2 Answers2

0

Form values are sent over HTTP using request parameters (for GET requests), with the input name attribute used to set the parameter "key". So your HTTP request will have the following params: ?iwd0_tax=userInput1&iwd0_discount=userInput2 etc.

Grails makes request parameters available by the params var in controllers:

def iwd0_tax = params.iwd0_tax

Grails can also populate a bean/class from the request params automatically. The bean is called a command object. See details in the Grails docs.

nickdos
  • 8,348
  • 5
  • 30
  • 47
  • thanks,but my question is how to get iwd0_tax iwd1_tax iwd2_tax as you see name attribute is an array format name I don't know how to iterate – user2985824 Mar 03 '14 at 23:10
  • `request params` can be sent as an array but the `name` attribute is usually the same for each element e.g. `iwd_tax=foo&iwd_tax=bar` - Grails can grab the List "version" with `params.list('iwd_tax')` but this won't work in your case as the array is implicit in the name, its not an actual array. So it come down to how you are creating your form inputs in the first place - it doesn't look very Grails-sy to me. – nickdos Mar 03 '14 at 23:20
  • This post may help http://stackoverflow.com/a/19462901/249327 - you'll need t parse out the array from the params yourself I think. – nickdos Mar 03 '14 at 23:32
0
def i = 0
while (params."iwd${i}_tax") {          
    println 'tax'+"${i}" + params."iwd${i}_tax"                     
    i++
}
uladzimir
  • 5,639
  • 6
  • 31
  • 50
user2985824
  • 65
  • 2
  • 5