Author
create multiple Checkboxes with data base values in jsp
Numay Hammad
Greenhorn
Joined: Jan 01, 2012
Posts: 4
posted Jan 01, 2012 07:05:01
0
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
posted Jan 02, 2012 00:23:11
0
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: 1008
posted Jan 03, 2012 17:31:10
1
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
posted Jan 04, 2012 00:03:18
0
thank you very much Stefan
i did what you said and it is working very well now
many thanks to you :thumbup:
subject: create multiple Checkboxes with data base values in jsp