Forget what I said last night about calling setInput() from the
ActionForm. Setting the input in the ActionForm's validate method
flagrantly violates Struts' MVC architecture; flow of control should
always be defined by the controller servlet and struts-config.xml. But
saving request scope variables as part of an ActionForm isn't always
an option. I think the best solution to Max's problem is to define the
input as the full path to the original action, then make sure that the
form coming from that page includes the necessary parameters to
recreate the original action page.
The following hypothetical situation should make this a bit clearer:
- You are running an online bookstore backed by a database. To display
books you have defined an action as "viewbook.do". The action takes
one parameter, an ISBN, so the user ends up seeing the url
http://server/viewbook.do?ISBN=123.
- On the book's page, you have a form asking users to rate the
book. Part of the rating form uses a select box generated from a
database of possible ratings (this list, all the possible ratings,
is the kind of request scope variable that one would *not* want to
store as part of a form; the list doesn't pertain to data the user
entered, it merely defines *possible* input values).
- When the user submits the ratings form, an ActionForm validates the
input. In struts-config, the input attribute for the "save ratings"
action is defined as "viewbook.do". Now suppose that the ratings
ActionForm generates errors... in order for the "view book" action
to successfully recreate the page that the ratings form was
submitted from, it needs an ISBN parameter. The solution to that
seems fairly simple--just drop in a hidden ISBN field in the ratings
form.
What I don't like about this solution is that information essential to
successfully defining the flow of control--a parameter that is part of
the definition of the input page--has to be in an HTML form. Perhaps a
feature for Struts 1.1 could be a special input value that signified
"use the form's HTTP referrer header, including all request
parameters, as the input for this form". Or, quite possibly, there is
an even more elegant solution that someone out there has discovered.
Cheers,
David
-----Original Message-----
From: Ted Husted [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, June 05, 2001 9:11 PM
To: [EMAIL PROTECTED]
Subject: Re: input in XML config
Could you create these request scope beans as properties of the
ActionForm?
David Noll wrote:
>
> Max,
>
> I don't know if it's the official way to do it, but in my ActionForm's
> validate() method, I call mapping.setInput() with the full path of the
> original Action. An important thing to note is that if your Action class
> pre-populates an ActionForm for the page, you should check for the
> ActionForm's existence before populating it.
>
> All that said, it does seem a bit cumbersome to go through all that merely
> to return to a dynamically generated input page if there are form errors.
> Does anyone on the list know of a cleaner way to achieve this?
>
> David
>
> --
> David Noll, Public Digital
> [EMAIL PROTECTED]
>
> -----Original Message-----
> From: LORENA MASSIMO [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, June 05, 2001 6:37 AM
> To: '[EMAIL PROTECTED]'
> Subject: input in XML config
>
> Hi,
> in an action mapping i'd like to reexecute the complete action instead of
a
> simple jsp when the validate method of the form fails, because i need to
> create some beans having request scope
> So my question is...
> Is it possible to have an action in the input fiele of a mapping instead
of
> a simple jsp?
> thanks Max