struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject Re: Initializing ActionForm beans
Date Fri, 18 Aug 2000 17:46:46 GMT
Hi Pierre,

If I understand your problem domain correctly, one possible fourth approach
would be to create a single form bean that is shared between the two actions,
containing a union of all the properties .  This approach is commonly used in
"wizard" style interfaces that extend over multiple pages, but are all logically
one "form".

Other than that, how is it decided that (A) is going to call (B)?  If it's done
in an Action -- which makes pretty good sense because this is a "controller"
type function -- then the Action itself can create the form bean that (B) needs,
and copy in the appropriate properties from (A)'s form bean, which is still
there in the session.

It seems to me that the details of what to do are going to be pretty application
specific.  If it is truly generic, yet another approach to consider is
subclassing ActionServlet itself, and overriding the methods that deal with the
form beans to copy stuff as you need it.


Pierre Métras wrote:

> Hi,
> I have a small conceptual problem using struts and I would appreciate any
> advice. My problem concern ActionForm bean initialization with
> special/dynamic values. According to the documentation, before displaying a
> form, struts will:
> 1) Obtain the bean if it exists from the user session
> 2) Create a new one if it doesn't exist and add it to the user session
> 3) Initialize the properties from request parameters
> 4) Populate the form field from the bean properties
> Imagine now that I have two different modules in an application, and I have
> created two ActionForm beans for them. Usually, users don't go in the two
> modules in a same session. But sometimes, a superuser can use the first
> module and then go in the second within the same work session. Some
> information is shared between the two modules, and in that case, I want to
> be able to initialize the shared information in one bean from the other one,
> in order to present a form partially completed.
> How can this be done? Let's call (A) the module with the ActionForm bean
> initialized, and (B) the module for which I want to initialize the bean with
> (A) values.
> I) From struts documentation, find all bridges between the two modules where
> (A) calls (B), and change the requests to put the shared parameters. Do the
> same thing for all calls to (A) from (B).
> The problem is 1) maintenance of all calls in (A), 2) the (B) bean is not
> always created in the first (B) form.
> II) Create JSP code in (B) form.
> I imagine such code would run after struts ActionForm bean initialization.
> The problem is that we go against struts philosophy in separating view and
> control, because the view contains some patching code to modify the bean...
> III) Create an ActionFormInitializer interface, with an
> init(HttpServletRequest request) method. Then modify processActionForm() in
> ActionServlet to call the init() method on the formInstance, if it supports
> the interface.
> Now, when the (B) bean is initialized, and only in that case, I can decide
> how to take into account (A) values and process specific initialization.
> Any advice?
> This problem can also occur in simpler situation. Imagine I use a secured
> logon with an automatic key: my bean can generate from the computer time and
> the workstation used a unique identifier that I want to display on the logon
> form. Then the user generates a one-shot password using that identifier to
> be able to log on. And for security reasons, I don't want to have the
> generated identifier as a request parameter...
> I can implement solution III) if no better alternative is found.
> Pierre Métras

View raw message