• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Form Bean not holding values across JSPs

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to JSP forum...
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
PVH
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jason,
Much appreciated. Seems to have done the trick...
Point noted about posting in the wrong forum.
Thanks again.
Pete
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic