• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts2: Retreiving values from list in execute() method

 
Rahul Yele
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want list of items to be displayed along with each having a blank textfield to fill amount on my jsp page and once I fill the required items amount, I will submit.
I have ExampleAction class as below, where I have populate() mtd which I fire first so that items are filled. I fire url :

Same ExampleAction has execute mtd which I call on SUBMIT button action from jsp page. But my problem is in execute mtd, I am unable to get the objects in list i.e. exList. Is this because an instance of the action class is associated with just one request? And when I fire another action through SUBMIT button there is different value stack associated? If yes, what should be the best possible ways for me to retrieve those amounts entered (in jsp), in execute() mtd to print in console of TomCat?
ExampleAction

EX.class

example.jsp

struts.xml

Please help me out, I am firing two actions:
1) populate.action : where I populate the exList
2)ex.action : which is triggered on SUBMIT button, to retrieve amounts entered in jsp against items , But I am unable to get any values, exList size is 0 in execute() method.

Thanks in advance.
 
Joe Ess
Bartender
Posts: 9214
9
Linux Mac OS X Windows
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And when I fire another action through SUBMIT button there is different value stack associated?


Every request has a unique value stack, however, that does not prevent you from mapping different actions in struts.xml to different methods in a particular action class.

The problem with getting the values back from your JSP is that you have no HTML form fields to hold the values. I suggest you look at this tutorial which does a good job of explaining how Struts works.
Lists require some extra work because you have to record in the JSP how to reconstruct the list when it is submitted back to your action. Once you've gone through the above tutorial and have a good grasp of Struts, have a look at this tutorial for an example on how to work with lists.
 
Rahul Yele
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem with getting the values back from your JSP is that you have no HTML form fields to hold the values. I suggest you look at this tutorial which does a good job of explaining how Struts works.
Lists require some extra work because you have to record in the JSP how to reconstruct the list when it is submitted back to your action. Once you've gone through the above tutorial and have a good grasp of Struts, have a look at this tutorial for an example on how to work with lists.


Thanks for the reply and for the two tutorials they cleared some concepts. But my problem is still not solved. I made the following changes
in ExampleAction class after reading the second tutorial but I am still not getting values in exList.
I am adding three EX objects to exList in populate() mtd but when I retrieve exList in execute() mtd and print size of exList it is surprisingly 2 and the two EX objects are null. I am really confused. Please help me out where I am going wrong.

 
Rahul Yele
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My issue is solved. Actually I made a mistake by making EX inner class so I made it public.
And there is no need to store exList in session.
Updated Code is below:
example.jsp


ExampleAction

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic