struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject Re: Extending struts classes
Date Sat, 14 Apr 2001 03:36:43 GMT


On Wed, 11 Apr 2001, Dmitri Plotnikov wrote:

> I was interested in the same issue and did not find a good solution, so
> I submitted a bug report:
> http://nagoya.apache.org/bugzilla/show_bug.cgi?id=1289
> 
> It does make sense for an ActionForm to have access to the context: not
> just the session, but also request, response, servlet context and
> servlet config.  ActionForms need to be able to access other beans held
> in the context, participate in i18n and do other context-dependent
> operations.
> 
> However, I understand that the whole issue of associating forms with the
> context is a gnarly one. These forms are accessed by both actions and
> JSPs.  JSPs access their context via PageContext, which conveniently
> aggregates all relevant pieces of context: request, response, session,
> servlet context and servlet config.  Actions, on the other hand do not
> have anything of that sort, they get all these pieces separately.  As a
> result of all this, it is unclear what the context-binding API on
> ActionForm should be.
> 

Yes, it is very gnarly.  One of the most important issues is that an
ActionForm instance can easily outlast a single request (if you are using
session scope), it is not reasonable to talk about a single request as
being relevant.  Also, if the application isn't using sessions, then there
is no relevant session either.

> Maybe we need to create a whole new object: StrutsContext and make it
> aggregate all levels of the context.
> 
> What do you think?
> 

The best strategy to deal with the orginally reported problem (wanting to
initialize form bean properties based on things stored in the user's
session) is to arrange your logic to *always* flow through an action that
creates and initializes the form bean, rather than going to the JSP page
directly.  That way, the form bean will always be there when the page
tries to access it, properly initialized.

The Struts example application illustrates this technique.  Consider the
registration.jsp page, where there are links to edit each
subscription.  The links are sent to the "/editSubscription" action, whose
job is to initialize the form bean for the selected subscription and
*then* forward to the appropriate JSP page (subscription.jsp).

> Dmitri Plotnikov
> CTO
> PLOTNIX, Inc
> 

Craig


Mime
View raw message