struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joe Germuska <...@Germuska.com>
Subject Re: Why doesn't ActionForm's constructor have access to HttpServletRequest?
Date Mon, 02 Feb 2004 23:42:26 GMT
>So... if I implement my own RequestProcessor class that overrides 
>the default processActionForm method to call my own 
>ActionForm-extending bean's constructor an explicitly pass it a 
>reference to the HttpServletRequest object so it can fetch the 
>HttpSession object and find the object that tells it everything else 
>it needs to know to pre-populate the form bean prior to display, am 
>I violating any sacred assumption made by other parts of Struts? Or 
>am I OK?

I do think that the original intention was to have ActionForm beans 
be lightweight and no smarter than they need to be (of course, they 
do have validate() and reset() methods.)   Most Struts classes use 
no-arg constructors, following the JavaBean specifications.

Generally speaking, I'm not sure that changing the request processor 
really helps you solve your problem, as Struts doesn't really 
directly handle the idea of an "output" form -- a form populated on 
the way to displaying a page.  The ActionForm you get in an Action is 
really an "input" form wrapping the request parameters.  In some 
cases you could have an ActionMapping which used the same type of 
form bean for input and output, but practically, this is rarely what 
you need -- more often, you step from one form to the next, unless 
you use a session scoped, multi-page form bean, which can work, but 
which can behave oddly sometimes too.

On my current project, we're experimenting with the struts-chain 
request processor, which makes controlling the overall request 
process cycle much much more flexible.  We've added in a "PagePrep" 
command between "execute action" and "process forward" that looks up 
a "renderer" based on the path in the forward config and executes the 
renderer before forwarding.  The renderer configuration is not too 
different from the action-mapping section of struts-config, and 
includes a form bean name and scope for the "output" form.  It would 
be rather harder to interpose this using the strict set of extension 
points defined by the RequestProcessor, but using struts-chain, it 
was very straightforward.

Note that struts-chain is still under development -- features like 
tiles and file uploads have just been added in the last few weeks, 
and it's possible that some other things don't work quite the way 
they do using the Struts 1.1 RequestProcessor.  But it really does 
work for most things, and the more that other people use it, the 
sooner it will work for everything!

Joe
-- 
Joe Germuska            
Joe@Germuska.com  
http://blog.germuska.com    
       "Imagine if every Thursday your shoes exploded if you tied them 
the usual way.  This happens to us all the time with computers, and 
nobody thinks of complaining."
             -- Jef Raskin

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message