How about this:

Do not blindly check for null ActionForm beans in all your Actions

If an Action expects an ActionForm bean, then its API contact with the
ActionMappings should require that a particular ActionForm bean, or
subclass thereof, be named in the ActionMapping. The Action's contract
with the controller is that it will always instantiate the bean before
the Action is called. If either contract is broken, the application
should expose a null pointer exception so that the programming error is
fixed and the misunderstanding resolved. Whether an Action expects an
ActionForm bean should be specified in its Javadoc.

Alternatively, the perform method should provide a general check of all
its preconditions, including, but not limited to, the existance of an
ActionForm bean. 

Do check for essential preconditions in your Actions

The perform method in the Action is a key hotspot in the framework, and
may be realizing several different API contracts. To be sure all the
contracts are being met, provide a general error catching routine for
your Actions. This can look for any number of preconditions including
whether there is a form bean when one is expected, and whether it is of
the requesite class, and provide the appropriate error messages. 

See the SuperAction class in the Scaffolding package for a working
example. Scaffolding can be found in the Contrib folder of the nightly
build.

-- Ted Husted, Husted dot Com, Fairport NY US
-- Developing Java Web Applications with Struts
-- Tel: +1 585 737-3463
-- Web: http://husted.com/about/services


"Carter, Steve" wrote:
> 
> On husted.com, Ted Husted wrote:
>                 Do not check for null ActionForm beans in your Actions
> If an Action expects an ActionForm bean, then its API contact with the 
>ActionMappings should require that this bean, or a subclass, be named in the 
>ActionMapping. The Actions contact wit the controller is that it will always 
>instantiate the bean before the Action is called. If either contact is broken, the 
>application should expose a null pointer exception so that the problem is fixed and 
>the misunderstanding resolved. Whether an Action expects an ActionForm bean should be 
>specified in its Javadoc.
> 
> Now I'm wondering if 'contact' was a type and what he meant was 'contract', that is, 
>in the sense of an API contract or implied constrain, pre-condition.
> 
> (You out there Ted?)
> 
> Anyway, this seems like a good idea. I'm always complaining that exceptions are 
>often overused or misused in Java, and this seems like a good use: let the exception 
>raise havoc, in order to inform you of a really exceptional condition, and one that 
>should be exposed if it exists.
> 
> Steve Carter
> Sr. Software Engineer
> Swift Rivers
> [EMAIL PROTECTED]
> 
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to