File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes How to Get the check box in html:checkbox automatically get checked on display . Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to Get the check box in html:checkbox automatically get checked on display ." Watch "How to Get the check box in html:checkbox automatically get checked on display ." New topic
Author

How to Get the check box in html:checkbox automatically get checked on display .

Satish Kumar
Ranch Hand

Joined: Oct 16, 2006
Posts: 85
I am using an int array to initialize the checkboxes when clicked.
I want to display them as checked. I do not want to use javascript etc.
Please suggest a way to get them checked. I am not using any boolean value in the bean rather its an integer array.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Here's an example:



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.


Merrill
Consultant, Sima Solutions
Satish Kumar
Ranch Hand

Joined: Oct 16, 2006
Posts: 85
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.
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
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:


- Brent
Satish Kumar
Ranch Hand

Joined: Oct 16, 2006
Posts: 85
Hi Brent,
I did not get how does this example is solving my problem.
Please brief if possible.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to Get the check box in html:checkbox automatically get checked on display .