• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts2 iterator

 
debraj mallick
Ranch Hand
Posts: 188
Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 485
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Put the students list in session.
 
debraj mallick
Ranch Hand
Posts: 188
Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Mohan Rao Sv,
is there any other solution other than putting it into session?
 
Mohana Rao Sv
Ranch Hand
Posts: 485
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 188
Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am also facing the same issue. Is there any other way of doing this?

Thanks,
Shikha
 
debraj mallick
Ranch Hand
Posts: 188
Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 188
Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
since i am having text boxes of same name, so in action i will get a String array with same name.
 
Shikha Dhawan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 188
Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Shikha.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic