| Author |
Struts2 iterator
|
debraj mallick
Ranch Hand
Joined: Mar 08, 2011
Posts: 188
|
|
hi all,
i have a bean name "Student" consists of name, address, age, mobile.
I can display all the students details in jsp by query the database and inserting each records in Student bean, so the Student list will look like
and the iterator in jsp is like
How can i get the student list in action so that i can iterate it and persist it into database. (i do have getters and setters of the list in action)
Any suggestion / Comments would be great.
|
 |
Mohana Rao Sv
Ranch Hand
Joined: Aug 01, 2007
Posts: 485
|
|
|
Put the students list in session.
|
ocjp 6 — Feeding a person with food is a great thing in this world. Feeding the same person by transferring the knowledge is far more better thing. The reason is the amount of satisfaction which we get through food is of only one minute or two. But the satisfaction which we can get through the knowledge is of life long.
|
 |
debraj mallick
Ranch Hand
Joined: Mar 08, 2011
Posts: 188
|
|
hi Mohan Rao Sv,
is there any other solution other than putting it into session?
|
 |
Mohana Rao Sv
Ranch Hand
Joined: Aug 01, 2007
Posts: 485
|
|
As per my understanding, you are sending studentlist from action class and displaying it in jsp file. Action action execution all the data in the valueStack will be nullified. So, you can't get the studentlist. Here you have 2 solutions
1) putting the data in session to reduce no of hits to the database.
2) Again make a database call.
3) you can use chain as result type. It will carry forward valueStack data to configured action. http://struts.apache.org/2.0.14/docs/chain-result.html
|
 |
debraj mallick
Ranch Hand
Joined: Mar 08, 2011
Posts: 188
|
|
hi Mohan Rao Sv,
thanks for your response.
you are correct that i am sending studentlist from action class and displaying it in jsp file where the user can make changes and when the user hit the update button the form is submitted,
all i need is the list with the updated values in action, since i am submitting the form i think i cannot use "chain" here because now my jsp is like
|
 |
Shikha Dhawan
Greenhorn
Joined: Jun 07, 2011
Posts: 10
|
|
Hi,
I am also facing the same issue. Is there any other way of doing this?
Thanks,
Shikha
|
Best Regards,
Shikha
|
 |
debraj mallick
Ranch Hand
Joined: Mar 08, 2011
Posts: 188
|
|
hi Shikha Dhawan,
i didn't find any good solution yet, at present what i am doing is - in action i have
once the user hits the submit button, i am getting all the values which solves my problem but still don't know how to retrieve / get the lists bean.
|
 |
Shikha Dhawan
Greenhorn
Joined: Jun 07, 2011
Posts: 10
|
|
debraj mallick wrote:hi Shikha Dhawan,
i didn't find any good solution yet, at present what i am doing is - in action i have
once the user hits the submit button, i am getting all the values which solves my problem but still don't know how to retrieve / get the lists bean.
HI Debraj,
You mean the name is of type String & an attribute of Student. Still it maps with the String[] name;
Thanks,
Shikha
|
 |
debraj mallick
Ranch Hand
Joined: Mar 08, 2011
Posts: 188
|
|
|
since i am having text boxes of same name, so in action i will get a String array with same name.
|
 |
Shikha Dhawan
Greenhorn
Joined: Jun 07, 2011
Posts: 10
|
|
debraj mallick wrote:since i am having text boxes of same name, so in action i will get a String array with same name.
Hi,
Your solution worked. But got a better way around.
While declaring the iterator :
Try . It worked.
Thanks Shikha
|
 |
debraj mallick
Ranch Hand
Joined: Mar 08, 2011
Posts: 188
|
|
|
Thanks Shikha.
|
 |
 |
|
|
subject: Struts2 iterator
|
|
|