wood burning stoves 2.0*
The moose likes Struts and the fly likes Struts2: Retreiving values from list in execute() method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2: Retreiving values from list in execute() method" Watch "Struts2: Retreiving values from list in execute() method" New topic
Author

Struts2: Retreiving values from list in execute() method

Rahul Yele
Greenhorn

Joined: May 24, 2014
Posts: 3
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

Joined: Oct 29, 2001
Posts: 8836
    
    7

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.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Rahul Yele
Greenhorn

Joined: May 24, 2014
Posts: 3
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

Joined: May 24, 2014
Posts: 3
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.
 
subject: Struts2: Retreiving values from list in execute() method
 
Similar Threads
How to retain the latest selected value of drop down box.
how to load a page properly ?
Two Seperate actions for one jsp page
Populating <html:select> tag
illegal argument exception error in struts