permaculture playing cards*
The moose likes Struts and the fly likes Form values when forwarding to an action Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Form values when forwarding to an action" Watch "Form values when forwarding to an action" New topic
Author

Form values when forwarding to an action

Victor Reese-Myan
Greenhorn

Joined: Aug 26, 2005
Posts: 4
I have an issue with my form values disappearing when I forward to an action.
It is my understanding that if you set scope="session" in your struts config, Struts will store your form in the user's session using the name provided in your struts config. Further, it is my understanding that when an action is called, it will search the session for an existing form and create one if it is not found. Am I right so far?

An overview of my situation (without getting too deep into the specifics of my code or project)... I have an action -- we'll call it ProcessAppAction -- that can be approached from two different ways. The first and simplest way is directly with ProcessAppForm being all null values. The second way is by being called from another action with a prepopulated ProcessAppForm. For instance, I might have an action called ProcessExistingAppAction that pulls values from a DB, populates a ProcessAppForm, stores it in the user's session as processAppForm (the name specified in the struts config), then forwards to ProcessAppAction.

Using the assumptions listed above, ProcessAppAction should check the session for an existing form and use it or create one if it is not found. My problem is Struts is ignoring the populated form I've placed into the session and replacing it with a reset()-ed form.

Any ideas?
Victor Reese-Myan
Greenhorn

Joined: Aug 26, 2005
Posts: 4
To elaborate:
"stores it in the user's session as processAppForm"

means:
Pranav Sharma
Ranch Hand

Joined: Oct 27, 2003
Posts: 258
the situation explained above should work.
maybe it is you action mapping. Are you sure struts is looking for the right Form.

session.setAttribute("processAppForm", processAppForm);

is "processAppForm" what you have in the "name" attribute of your action mapping

<action path="/ProcessAppAction" type="source.actionSource" name="processAppForm">
Victor Reese-Myan
Greenhorn

Joined: Aug 26, 2005
Posts: 4
Yes, I am absolutely sure. I've checked it, rechecked it, then copy/pasted it to eliminate any potential typos.

I think I'll throw some loggers in to see if ProcessAppAction is overwriting my stored form with a new form instance or retrieving my existing form and calling reset().
Pranav Sharma
Ranch Hand

Joined: Oct 27, 2003
Posts: 258
Sorry, after reading the post again could you tell me ..

why is your processAppExistingAction after populating the form, calling another (processAppAction) action. It should be calling the jsp page.
I'm guessing your form gets reset by struts when you call the next action.

if processAppExistingAction calls the jsp it should get populated.
you may also have to work into designing the flow. try to keep it
Action 1-> JSP 1 -> Action 2 -> Jsp 2.
[ August 26, 2005: Message edited by: mannu kapoor ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Form values when forwarding to an action