Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Form values when forwarding to an action

 
Victor Reese-Myan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To elaborate:
"stores it in the user's session as processAppForm"

means:
 
Pranav Sharma
Ranch Hand
Posts: 258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic