The moose likes JSP and the fly likes Is this A bean or db design problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "Is this A bean or db design problem" Watch "Is this A bean or db design problem" New topic
Author

Is this A bean or db design problem

Anthony Smith
Ranch Hand

Joined: Sep 10, 2001
Posts: 285
I have a set of chkboxes on a jsp page. These checkboxes values are givien from a db. So I call a loop to show checkboxes. Problem being, is tat on my other jsp page that I allow to modify it, I would like to use the most effcient way to show all the checkboxes and which ones were checked an unchecked from the last time.
I will attempt to show some pusedocode just in case I lost anyone.
add.jsp
*******
1. Loop that prints checkboxes and their values.
2. For gets send to servlet and inserts the ID of those that were checked
modify.jsp
********
Needs to show all chckboxes with onyl the ones with reocrds in the db checked...
Will this invlove 2 for loops or is their a better way?
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
pal ii am making a few assumptions
1)The number of checkboxes on u'r screen are not dynamic ,i.e. there are a fixed number of check boxes on u'r screen.
2)You are checking the checkboxes in Add mode and their state is getting saved in the Database .
3) In update mode u want to display the chechBoxes with state populated from the database .
U could go about it in this fashion .Execute a query when u call enter the jsp in Update mode which query's the database for the state of the checkBoxes.
Form a delimited String on the server with values from the resultset . Typically it's gonna look like
Y%Y%N%N%Y where Y stands for a checked checkBox & N for a unchecked CheckBox & % is a delimiter . Assign this java Array to a javaScript array .
using split() function .
Now u can assign the values to individual checkBoxes using javaScript in a function called on body onLoad().....
Please mail if u need any further clarifications.
Sachin
Anthony Smith
Ranch Hand

Joined: Sep 10, 2001
Posts: 285
I got your answers to the post but the # of checkboxes will be dynamic cause the values of the checkboxes are coming from the db, and some can get added to make more checkboxes. When I go to update, I still want all of my checkboxes to appear in the same place, ut I want some to seem checked and the other to be blank
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Is this A bean or db design problem
 
Similar Threads
Kindly help with servlet jsp interaction
checkboxes persistence
The selected checkbox should be checked
dynamic Checkboxe value retrieval
maintin checkbox stauts during paginatin(dispalytag)