ironmantis7x ironmantis7x - 10 months ago 67
Groovy Question

How to get a list of checked boxes in grails

In grails, I am trying to get a list of checked check boxes.
I have the list of check boxes, but my issues are two:

1) when I click on a single item in the list and click submit - I only get the value "on". If I click more than one check box item, I get something like this:


2). I do not get a list or the name of the item checked.

Here is my code for the check boxes in the gsp:

<g:form action="submitForm">
<ul class="columns3">
<g:each in="${name}" var="fileName" >
<g:checkBox value="${false}" name="${ 'fileName'}" /> ${fileName.replaceFirst(~/\.[^\.]+$/, '')}<br>
<g:submitButton name="Submit"/>

and here is the controller code (groovy):

class Read_dirController {

def index() {

def list = []

def dir = new File("/home/ironmantis/Documents/business/test_files")
dir.eachFileRecurse (FileType.FILES) { file ->
list << file

list.each {
println\.[^\.]+$/, '')

render(view: "index", model: [])



def displayForm() { }

def submitForm(String fileName) {
render fileName
//render(view: "tests_checked", fileName)

I tried to bind an id to the check boxes, but I keep getting an exception error.

Any help you can give I truly appreciate it; I am new to grails.



This way,

def submitForm() { 
def values = request.getParameterValues("fileName") 
//here values contains string array which are selected in checkbox