The above code assumes you have a property named picks of type int in your ActionForm. Prior to displaying this page, populate the picks property with some values and the correct values will be checked. For example, if picks contains "1, 2", Boxes one and two will be checked, while box three will be unchecked.
hi Merrill, Thanks for the reply. I got it working and i am getting the checkboxes as checked when the value matches. This involves hardcoding the values though.. HENCE this alone is not solvin my problem as the values are coming dynamically and assigning the formbean property with the values at declaration is not practical. I have the values (an arraylist in an object) with me in the request scope. I need to have a way to get these values somehow assigned to the bean variable. As far as i guess this code will go inside a JSP. I am not able to figure out as how do i do this in the JSP i.e. populating the bean variable (integer array) for checkbox with the values from an arraylist.
I typed up a quick response...and then I tried jumping over to Google and searching on the phrase "html:multibox example" and the very first hit was an example of almost exactly what I typed.
oh well...here is my example:
posted 13 years ago
Hi Brent, I did not get how does this example is solving my problem. Please brief if possible.
posted 13 years ago
I have the values (an arraylist in an object) with me in the request scope. I need to have a way to get these values somehow assigned to the bean variable. As far as i guess this code will go inside a JSP
This code should not go in a JSP, but in an Action class that forwards to this JSP. Just write code to copy the values from wherever they are into a String array within your Actionform.
suppose you have an ArrayList of MyBean objects, and that the id property of each MyBean object should constitute the list of which check boxes are checked and which are not. The following code would work:
In order to dynamically create a set of checkboxes, you would use code similar to the example that Brent gave.