Hi all,

while implementing a few multipage forms some questions came up to my mind.

>From my experience, multipage forms typically are handled like this:
- User requests first page (n=1) of multipage form
- Form bean is created (either by jsp or by action)
- Send page (n) to the client
- Client enters data and submits to corresponding Action
- ActionServlet retrieves the bean   (*)
- ActionServlet reset's the bean     (*)
- ActionServlet populates the bean   (*)
- ActionServlet validates the bean   (*)
- ActionServlet calls action.perform (*)
- Action.perform checks if it's the last page of the form.
  If not, it just forwards to the next page (n=n+1).
  Otherwise, the _real_ action is performed (probably after
  some additional validation)
(Sometimes, also the first page is retrieved through an action).

This is easy to implement and requires only one Action and no custom
mapping or custom ActionServlet.


Things are getting more complicated if the path the user takes through
the form pages depends on the users input. For example, if I want to
create shopping app where the user can decide on the first page, if he
wants to buy a book, a car or a cd and the second page displayed to the
user depends on (t)his decision, than I have problem.

The problem is, that if the user makes an input error on page #2, I have
to show the previous (ie. CD, car or book) input page. But ActionMapping
has only one input page. So, this leaves me with either implementing
custom ActionMapping classes, overriding some ActionServlet functionality
or defining many Action's in the struts-config - one for each possible
previous/next page pair.

>From my opionion, the above mentioned "solutions" are ugly, because they
- depending on the number of multipage-forms, steps in each form and
possible trails through each form - lead quickly to either a very large
number of classes or an unmanagable struts-config.xml. Using an extended
ActionServlet isn't really a solution, because it may break compatibility
with future Struts builds.


An alternate solution without the drawbacks would be to move the ActionForm
related stuff from ActionServlet to Action. For example, ActionServlet
could just do the lookup of the Action and than call a new method action.handle().
Action.handle() in turn should do those steps marked above with (*).
This would allow the developer to adapt the Action class (that he/she
has to implement anyway) to his/her needs (by overriding action.handle()
or one of the methods called from action.handle()) or to otherwise use the
default action.handle() implementation, that would behave like the code
currently located in ActionServlet.


Comments ?

-- 
Matthias                          mailto:[EMAIL PROTECTED]


Reply via email to