views:

68

answers:

1

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.

+1  A: 

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
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
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