aspose file tools*
The moose likes Struts and the fly likes Problem reading multiple rows of data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Problem reading multiple rows of data" Watch "Problem reading multiple rows of data" New topic
Author

Problem reading multiple rows of data

Nitya Sharma
Greenhorn

Joined: Nov 09, 2003
Posts: 3
Hi,
How do I read multiple rows using struts?
Each row has 2 fields. And I have to read 10 rows from the page.
I tried using iter tag. I used a value object with 2 fields, I used an ArrayList(list) to store those value objects. I created arrayList of size 10 and added it to the form and added that form in session in the earlier action class.
It is displaying 10 rows with 2 cols. but when I fill in the data and submit
I will not get anything from the form in the action.

My question is can we use iter tag to read as we use for display?


What other alternatives do I have to read this kind of form
Thanks ,
Nitya Sharma
Tzanko Stefanov
Greenhorn

Joined: Nov 14, 2003
Posts: 4
Here is an idea - should work, but let me know if so.
Create a getter/setter
setAge(int i) - It will put an element in a Collection on the position provided by i (so you will have a private Collection data member in your form). The same thing should be done for your name property.
Now modify your code accordingly
<logic:iterate id="id" name="nameForm"property="list" indexed="idx"><TR><TD><html:text name ="id" property="<%="name"+idx>" /></TD><TD><html:text name ="id" property="<%="age"+idx>" /></TD></TR></logic:iterate>
I cannot test it now but smth tells me that this is one possible option (or at least smth simillar). I appologize if I am providing misleading info here.
Tzanko Stefanov
Greenhorn

Joined: Nov 14, 2003
Posts: 4
sorry I made a mistake
<logic:iterate id="id" name="nameForm" property="list" indexed="idx"> <TR> <TD><html:text name ="id" property="<%="name["+idx+"]">" />....
instead of having setAge(int)/getAge(int) you can return a collection instead. For example:
public java.util.List getAge()
Nitya Sharma
Greenhorn

Joined: Nov 09, 2003
Posts: 3
Thanks for your reply.
It did not work, looks like I am missing something here.
Can you please write how do you write the form Bean
Thanks,
Nitya Sharma.

This is what I tried...
<logic:iterate id="id" name="skillForm" property ="names"
indexId="index">
<TR>
<bean:write name ="id" property='<%= "names[" + index + "]" %>' />
</TR>
</logic:iterate>
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Problem reading multiple rows of data
 
Similar Threads
Nasty code pls
Update user profile
Validation rule for array of objects.
retrieve value of a field
Nested Iterator Tags