File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Populating checkboxes in a JSP page with values from DB  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Populating checkboxes in a JSP page with values from DB  " Watch "Populating checkboxes in a JSP page with values from DB  " New topic
Author

Populating checkboxes in a JSP page with values from DB

Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
I want to populate some check boxes with apropriate values retrieved from a DB. I have a group of check boxes with the same name. (i.e. multiple can be selected). I know I probably need to get the parameter name before I can access it, but only checked checkboxes are passed back to the server using getParameterValues, and I need access to the entire checkboxes so that I can mark the appropriate ones as checked.

Thanks, Bosun


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

I face a similar situation. What I'm thinking of doing is including a count of how many should be there. Each check box is named the same, but it's value relates to the PK of the table.

Then I can run through each returned value, and use the id as an array index. The array contains all possible values (the count of how many there should be), but my checkboxes will only turn on certain array elements. Then I can cycle through this array and see which ones are 'true' and which are 'false'.

This is off the cuff. Anyone have a different idea.?
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Thanks for the response. The solution I went with is calling a java method when the form is being painted. This method accesses the arrayList of checkboxes that should be checked, and then returns a boolean if the checkbox should be checked or not. Based on the value returned, I check/do not check the checkbox.
ex. <% myMethod(chackBoxValue) ? "CHECKED" : "" %>
where mymethod is called with the value associated with the particuler checkbox.

Thanks, Bosun
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Populating checkboxes in a JSP page with values from DB