• 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
  • 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 a Form with iterating rows, with the same data

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to create a form (in JSP or HTML) with a "List" of data.
Each row has the same data.
For example a row has a person-id, name and a checkbox.

I want to program a servlet to handle the "List", created in the form. (something lik: while list.next() .... do something)
so I can perform activities for each row (depending on the value of the checkbox.)
Can anybody give me an example to resolve this problem?

thank's!
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using that the data you will be showing in rows is coming from a database.So,you will be using a ResultSet.

Use a while loop to create the rows.
If fetchRS is the ResultSet then the code is like this :


 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you give some details of the architecture that you are following? This is because, the implementation will vary depending on the environment.
How are you retrieving the values from DB?

In case of Hibernate, you directly get a list of objects from the DB which can be set in a form property and used to display the list on JSP by iterating over the form property.

A little more clarity from your end will help in providing an optimum solution

Thanks and Regards,
-------------------------------------------------------------------------------------
Komal Renu | krenu@infocepts.com | www.infocepts.com
-------------------------------------------------------------------------------------
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Result sets should never be used in the controller or view layers. The data should be copied into Java collections and the result set closed immediately.
 
mark reusen
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All,

I'm working conform the MVC pattern and retrieve the data from a sessionAttribute.
The sessionAttribute keep a ArrayList of a MySQL table.
So on the form I retrieve the data from the ArrayList (set in an sessionAttribute), and present it with use of EL.

regards,
Mark
 
Komal Renu
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mark, You could use <logic:iterate> to iterate over the list and then <bean:write> to write the values on JSP.

Thanks and Regards,
-------------------------------------------------------------------------------------
Komal Renu | krenu@infocepts.com | www.infocepts.com
-------------------------------------------------------------------------------------

 
mark reusen
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Komal,

write is not the problem, perform the checkbox is the problem.
first I present the data (which I retrieve from the sessionAttribute), then I want to perform the chckbox which is filled in the form.

regards,
Mark
 
Komal Renu
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok..

If i get it correct, you must be using a list of objects. ArrayList(obj1, obj2, ... )

now, on your JSP, you can assign the checkbox a value as chk_<some unique identifier>.
When the user selects the checkboxes and clicks on submit, then in Javascript iterate over all checkboxes and pick up the selected ones, put them in an array and set this in a form property.

One you reach the servlet, you will have the selected checkbox ids from this property and then you can fetch the corresponding objects for those by iterating over the ArrayList and perform the actions required.

Let me know if you need more detail.

Thanks and Regards,
-------------------------------------------------------------------------------------
Komal Renu | krenu@infocepts.com | www.infocepts.com
-------------------------------------------------------------------------------------
 
mark reusen
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank's Komal!

regards,
Mark
 
Live a little! The night is young! And we have umbrellas in our drinks! This umbrella has a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic