You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Palmer, Nick" <np...@APEngines.com> on 2001/07/23 21:53:31 UTC

Mulitpage form support.

When working with multipage forms it is desirable to have one bean in the
users session that is populated as the user goes through the various pages
of the form. 

I mistakenly thought that this was one of the services that struts provides.
I have now discovered that this is not the case. When a form is submitted
Struts seems to blindly replace the previous bean with a new one and then
populates the new one with only the values that are on that particular form.
(Is there something I am missing?) The only way I can get it to work is to
put hidden fields in the form so that the data entered on one page is
populate back into the bean again when it is submitted. The only other
option I see is to have a single bean for each page, but this is not a
desirable solution. Is there some other solution? Perhaps by storing the new
bean in the request instead of the session, and then copying the values into
the session bean? This seems like a big pain too!

Adding hidden fields to each form means that one either has to put all of
the fields of the bean into every form (which is a big headache if you want
to add a field) or you have to put all the fields in that have been entered
so far (which is a big headache if you want to change the flow of the
pages.) 

It seems to me that the population of values into a bean should be proceeded
by a check to see if there is a bean in the users session. If there is then
that beans set methods should be called. This would make it so much easier
to create multiage forms, and would not require the user to add all the
hidden fields to a form. This is what I thought struts did when I started
using it, and I am disappointed that this is not the case.

-Nick

Re: Mulitpage form support.

Posted by Gregor Rayman <gr...@gmx.net>.
Try using "session" scope instead of "request".

--
gR



Re: Mulitpage form support.

Posted by Ted Husted <hu...@apache.org>.
Struts calls the reset() method on any bean before populating it from a
request. This is to allow general reuse of beans, and to be sure some
controls like checkboxes are handled properly.

You may need to be sure that the reset() method for your session-bound
ActionForm bean does not blindly clear the properties that other pages
have already populated. 

Deft handling of multipage wizard-type forms (not be confused with
multipart forms used for uploading files) has always been a problem in
Struts. I don't use them myself, but if someone who does would like to
contribute an article, it would make a nice addition to the Users Guide.
Something that also used that "page" property in the ValidatorForm class
would be excellent!


-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel 716 737-3463.
-- http://www.husted.com/about/struts/


"Palmer, Nick" wrote:
> 
> When working with multipage forms it is desirable to have one bean in the
> users session that is populated as the user goes through the various pages
> of the form.
> 
> I mistakenly thought that this was one of the services that struts provides.
> I have now discovered that this is not the case. When a form is submitted
> Struts seems to blindly replace the previous bean with a new one and then
> populates the new one with only the values that are on that particular form.
> (Is there something I am missing?) The only way I can get it to work is to
> put hidden fields in the form so that the data entered on one page is
> populate back into the bean again when it is submitted. The only other
> option I see is to have a single bean for each page, but this is not a
> desirable solution. Is there some other solution? Perhaps by storing the new
> bean in the request instead of the session, and then copying the values into
> the session bean? This seems like a big pain too!
> 
> Adding hidden fields to each form means that one either has to put all of
> the fields of the bean into every form (which is a big headache if you want
> to add a field) or you have to put all the fields in that have been entered
> so far (which is a big headache if you want to change the flow of the
> pages.)
> 
> It seems to me that the population of values into a bean should be proceeded
> by a check to see if there is a bean in the users session. If there is then
> that beans set methods should be called. This would make it so much easier
> to create multiage forms, and would not require the user to add all the
> hidden fields to a form. This is what I thought struts did when I started
> using it, and I am disappointed that this is not the case.
> 
> -Nick