Take the 2-minute tour ×

Here's how I'm doing it. There has to be a better way.. I hope.

I'm using a jsf datatable to display my data. The first column in each row is a checkbox.

Multiple checkboxes can be selected. When the submit button is hit I'm using javascript/jquery to get all of the checked boxes and get that rows ID which is a string.

In my js I'm concatenating all of the IDs into one string separating them with a comma. Then I set the value of a hidden input on my jsf/jsp page to the concatenated string. In the backing bean I extract all of those IDs from the Strings and create a List of Strings.

I'd like to be able to create the list in my javascript, pass that list of Strings to the backing bean somehow, maybe hidden input still, and avoid the string concat.

I'm using jsf1.2 if that matters.

Thanks for your suggestions. Code examples are appreciated, but not necessary.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

You could let JS fill a <h:inputHidden>.

<h:form id="form">
    <h:inputHidden id="ids" value="#{bean.ids}" />
    // ...


document.getElementById("form:ids").value = yourCommaSeparatedString;

You could create a Converter which converts a comma separated String to String[] and vice versa so that you can make ids a String[] property. You can find a basic example here: taking multiple values from inputText field separated by commas in JSF.

Unrelated to the concrete question, that's a bit hacky. Just use <h:selectBooleanCheckbox> with a Map<Long, Boolean> or something. This way you don't need to throw in any JS code. See also How to delete many row in <h:dataTable> with checkbox.

share|improve this answer
Your "unrelated" comment is exactly what I'm looking for. I was looking for something that wasn't so hacky/didn't require JS. Thanks a ton! –  Dale Dec 22 '11 at 3:40
You're welcome. –  BalusC Dec 22 '11 at 4:04
add comment

Your Answer


