aspose file tools*
The moose likes JSP and the fly likes create multiple Checkboxes with data base values  in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Reply locked New topic
Author

create multiple Checkboxes with data base values in jsp

Numay Hammad
Greenhorn

Joined: Jan 01, 2012
Posts: 4

hello

happy new year :D

i faced some problem while i am trying to create a multiple check boxes that comes from data base

this is my code .. in the jsp page .. that takes list of books comes from the local interface

and try to view books as chickboxes using For loop



and every thing is going fine ,but it shoes only the last book in the checkboxes

for example if there is 3 books in the list let's say( book1 , book2 and book3 )

it only shows the last book three times in checkboxes like this :

[] book3
[] book3
[] book3

and i don't know what is the problem , is it because the Iterator or not ??

and i am sure that my list has all 3 books ( i tested it )

i really need your help here :)
Numay Hammad
Greenhorn

Joined: Jan 01, 2012
Posts: 4

hello

i found the mistake

the problem was when i bring the data from DB it comes as result set .. and i want to convert it to a list so i used this function



and i think this function was the problem ( i do not know where )

so i tried to convert the resultset to array of string

and i made the required changes to the classes and the jsp file

and it worked !!!

this is my new jsp file





many thanks to everyone who tried to help :)


Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
That function was the problem.
You need to create a new "book" object for each iteration of the loop.

ie instead of



It needs to be:



Otherwise you just keep adding the 'same' book object multiple times to the list, and overwriting the old values with new ones.
Which is why it looks like a list of just the 'last' book.

It is a common mistake that many of us have made along the way.
Easily made, and easily solved (once you know what to look for)
Numay Hammad
Greenhorn

Joined: Jan 01, 2012
Posts: 4

thank you very much Stefan

i did what you said and it is working very well now

many thanks to you :thumbup:

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: create multiple Checkboxes with data base values in jsp