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

create multiple Checkboxes with data base values in jsp

 
Greenhorn
Posts: 4
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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
Posts: 4
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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 :)


 
Bartender
Posts: 1845
10
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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
Posts: 4
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
thank you very much Stefan

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

many thanks to you :thumbup:

 
    Bookmark Topic Watch Topic
  • New Topic