• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Struts2: Retreiving values from list in execute() method

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic