File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Form Bean not holding values across JSPs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Form Bean not holding values across JSPs" Watch "Form Bean not holding values across JSPs" New topic
Author

Form Bean not holding values across JSPs

PVH
Greenhorn

Joined: Jun 13, 2003
Posts: 5
Hi all,
I have created a form which spans multiple JSP pages, but uses the same form bean each time. The problem is that unless each jsp contains form fields for ALL the data contained within the ActionForm, the data is not passed from JSP page to jsp page. Only the data contained in the most recent page is set, and the other data set previously is overwritten.
Here is a very simple example of what I mean:
----ACTION FORM----
public class CreateSourceProfileForm extends ActionForm {
Profile currentProfile;
public Profile getCurrentProfile() {
return currentProfile;
}
public void setCurrentProfile(Profile newProfile) {
currentProfile = newProfile;
}
}
----JSP 1----
.....
<html:text name="FormName" property="currentProfile.name" />
.....

----JSP 2----
.....
<html:text name="FormName" property="currentProfile.address" />
.....

----ACTION----
.....
Profile p = form.getCurrentProfile();
return mapping.findForward("Page2");
.....

When the form is submitted again from Page 2, the information submitted in Page 1 no longer appears, only the information contained on Page 2. Has anyone any ideas on this? I am not able to pass data in the session, as the actual form spans 10 pages and may take a while to complete. As the data will be accessible by concurrent users, I need to ensure it's integrity.
All advice gratefully received.
Many Thanks,
Pete
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
Moving to JSP forum...


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61420
    
  67

Where and how are you storing and accessing the bean? If it's in request scope, then of course you will get a new instance of the bean with every request.
hth,
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
PVH
Greenhorn

Joined: Jun 13, 2003
Posts: 5
Bear,
Thanks for the reply.
In each of the JSPs I set the scope of the from as 'session' :
<html:form action="/createProfile" method="post" name="CreateSourceProfileForm" type="CreateSourceProfileForm" scope="session">
I test in the CreateSourceProfileForm to see whather the attribute 'profile' is null each time I use the accessor methods, and each time, despite the fact that I have set the attributes from the previous JSP, it confirms that 'profile' is null.
Any other clues?
TIA
Pete
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61420
    
  67

Are you getting a new session each time? That might account for a new bean being created each time. (I assume you've already tested to see that a new bean is being created on each hit?)
Check to make sure the session cookie is being maintained.
hth,
bear
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
Originally posted by Pete Inchley:
In each of the JSPs I set the scope of the from as 'session' :
<html:form action="/createProfile" method="post" name="CreateSourceProfileForm" type="CreateSourceProfileForm" scope="session">

The scope attribute of the <html:form> tag has been deprecated. The scope is now only determined by the corresponding ActionMapping in the struts-config.xml.
Just FYI, Struts questions should generally be posted in the Java Frameworks forum.
PVH
Greenhorn

Joined: Jun 13, 2003
Posts: 5
Jason,
Much appreciated. Seems to have done the trick...
Point noted about posting in the wrong forum.
Thanks again.
Pete
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Form Bean not holding values across JSPs