I'm working on an application that has one page for the user to fill in a form and submit it, and a second page to display results. If there are any validation errors in the submitted values, I catch these in a
servlet (actually a portlet), set the submitted values to request attributes, and then redisplay the form page. I have the input fields set to fill in with these attributes, so a text input field looks like:
(I'm working with an ancient version of JSPs -- from
JEE 1.3 I think -- so EL only works inside c: tags.)
So that works well. However, we've recently added multichoice selections implemented as checkboxes with a common name, so something like:
When the form is submitted, I get a request parameter "choices" with an array of Strings showing which checkboxes were checked. I'd like to restore the checked state of these boxes if there is a validation error with one of the other fields, but I'm not sure how to do it. Ideally, there would be EL like:
but I don't think there is. The best solution I can think of is to create a CSV
string of all the previously selected items, put it in a hidden field, and then have a JavaScript load function parse the string and set up the checkboxes. Is that a reasonable approach, or am I missing something that would be much easier?