• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Populating checkboxes in a JSP page with values from DB

 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic