aspose file tools*
The moose likes JSP and the fly likes Create a Form with iterating rows, with the same data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Create a Form with iterating rows, with the same data" Watch "Create a Form with iterating rows, with the same data" New topic
Author

Create a Form with iterating rows, with the same data

mark reusen
Greenhorn

Joined: Oct 20, 2010
Posts: 22
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

Joined: Feb 14, 2010
Posts: 21
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

Joined: Jul 21, 2011
Posts: 51
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

Joined: Jan 10, 2002
Posts: 60041
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
mark reusen
Greenhorn

Joined: Oct 20, 2010
Posts: 22
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

Joined: Jul 21, 2011
Posts: 51
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

Joined: Oct 20, 2010
Posts: 22
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

Joined: Jul 21, 2011
Posts: 51
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

Joined: Oct 20, 2010
Posts: 22
Thank's Komal!

regards,
Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Create a Form with iterating rows, with the same data
 
Similar Threads
access rows from html table
creating html form dynamically using logic:iterate
Html form to form bean mapping, multiple checkboxes
Best option to update only selected rows form Struts2
set checkbox "checked" when a value in an selectbox changes