This is what I have in table:
<td><g:checkBox name="book_${bookInstance.id}"/> </td>
And this is how I try to get selected instances:
params.each{
if(it.key.startsWith("book_"))
books << (it.key - "book_") as Integer
}
I'm getting an empty list. How to fix this? I'm open to suggestions if u have a better solution.
Try creating the list of checkboxes with all the same input name, but different values.
<g:each in="${books}" var="bookInstance">
<g:checkBox name="books" value="${bookInstance.id}"/>
</g:each>
Then in your controller you can get the list of selected book IDs via:
params.list('books')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With