Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Populating checkboxes in a JSP page with values from DB

 
Ranch Hand
Posts: 1512
  • 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: 1512
  • 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
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic