0

I have a struts2 action that builds a form and pre-populates the fields with data from an instance of my object. When I click submit on this form, I get taken to a second action, my formSubmit action. Here I'd like the object to be updated with any new values from the form. Is there an easy way to access this same object in my second action in struts2?

I'd like to, if at all possible, keep my object in request scope, rather than session.

Roman C
  • 49,761
  • 33
  • 66
  • 176
jcovert
  • 550
  • 1
  • 7
  • 21
  • 2
    You can't keep it in the request scope. The second action concerns a brand new and completely different HTTP request. The object from the initial request is already for long been garbaged when the associated response was finished. Either just create a new object or store in session. I don't do Struts, so no detailed answer from me how exactly to do that. – BalusC Jun 17 '10 at 16:09

1 Answers1

1

I'd like to, if at all possible, keep my object in request scope, rather than session.

Well, it is not possible. Think of it: a "request scope" is born when the request starts (the user clicks a button) and dies when the request (the same request, obviously) ends (when the data is sent to the browser). You want to keep an object in a longer-lived scope (probably the session). Or, if the data comes from a DB, load it again in both requests (using perhaps some optimistic locking if are concerned about concurrent changes). These are the typical ways of doing it.

leonbloy
  • 73,180
  • 20
  • 142
  • 190
  • I think he's still looking for an answer how to do that in the session scope. Or am I mistaken and is just setting it to session scope enough? (as in JSF) – BalusC Jun 17 '10 at 18:53
  • Alright yes, can I use session scope to update objects from a form? I have created a related, more specific question: http://stackoverflow.com/questions/3719614/struts2-form-to-update-object-in-session-map – jcovert Sep 15 '10 at 18:38