struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Skubick <>
Subject Accessing session-context objects within ActionForm's constructor
Date Mon, 02 Feb 2004 21:03:48 GMT
OK, I think I might have found an example illustrating nested formbeans that
shows how to use nested settable formbeans(the Bananas, Inc. web app at

Apparently, the proper procedure is to create a container bean object that
encapsulates the entire collection of user-representing bean objects, create
an instance of that bean in the ActionForm constructor, and make the get/set
methods of the ActionForm handle instances of the container bean. For
illustration, let's call the bean MyContainerBean, and call the ActionForm
that handles it MyActionForm.

This brings up one or two new problems. Apparently, the instance of
MyContainerBean is what should have the List of bean objects that represent
the users (ChangeableUserBean objects... with get/set methods for userId,
foo, and bar). The List of ChangeableUserBean objects needs to be created
when MyContainerBean itself is constructed. The catch is, that data is in
the database, and the subset of users that will be used to populate that
list of bean objects depends upon the user for whom the MyActionForm bean is
being created in the first place.

Put another way, suppose Bob and Mary are both logged in users of the web
app, and both trigger Actions that result in their being forwarded to jsp
pages with forms whose ActionMapping is associated with MyActionForm
ActionForms for the first time. At that point, Struts needs to create
instances of MyActionForm for each of them so the <nested> tags in the jsp
page itself can fetch values from them to render the initial html form for

Stepping back for a moment, both Bob and Mary logged in a while ago, and had
HttpSession objects created on their behalf and bound to their respective
sessions. Furthermore, they both have an instance of an AdministrableUsers
object (which contains everything MyContainerBean needs to know in order to
build its list of administrable users) saved in their session as

So... now for the big question... without obvious access to the user's
HttpSession object (from which it could easily fetch the user's instance of
"administrable_user_object") or the HttpServletRequest that triggered the
creation of a new instance of MyActionForm in the first place (from which
the HttpSession object could be fetched), how exactly can the constructor
get a hold of that object so it can initialize the ChangeableUserBean object
and use it to render the initial jsp form?

Somehow, I've got a suspicion that it involves taking advantage of one of
ActionServlet's official extension points to override the method that
creates the ActionForm, but I'm still hoping there might be a metaphorical
wire or two hanging from ActionForm's "ceiling" that, if followed back far
enough, might lead to an object with direct access to the HttpServletRequest
that triggered its invocation in the first place, or the HttpSession object
of the user for whom the ActionForm-extending object needs to be created.

Is there?

----- Original Message ----- 
From: "Sandy Bingham-Porter" <>
To: "Jeff Skubick" <>
Sent: Monday, February 02, 2004 2:00 PM
Subject: index and nested form beans

> Hi Jeff,
> If you should get any solutions to your questions concerning nested form
> beans, would you pass them my way.  We have the same questions.  I
> posted a similar question last Friday and have received no responses.
> Thanks for any help,
> Sandy Bingham-Porter
> Financial Systems Manager
> Eastern Illinois University

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message