File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Create a Form with iterating rows, with the same data

 
mark reusen
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • 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!
 
rajarshi roy
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • 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 :


 
Komal Renu
Ranch Hand
Posts: 51
  • 0
  • Mark post as helpful
  • send pies
  • 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
-------------------------------------------------------------------------------------
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64200
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank's Komal!

regards,
Mark
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic