Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Problem reading multiple rows of data

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic