You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Anand Raman <an...@mymailbag.com> on 2001/02/02 07:48:14 UTC

can a ActionForm be ever null in Action class

Hi guys

I noticed in the struts-example application a check to find whether the
ActionForm "form" passed to the perform method of Action class is null or
not.

Is it really necesarry.. I am not able to come up with a situation like
this.. According my knowldge a ActionForm is always populated before the
perform method is called on the Action class..

can anyone please enlighten this situation


Thanks for ur time
Anand

RE: can a ActionForm be ever null in Action class

Posted by Philip Hart <ha...@ubusiness.co.uk>.
Hi All

Just a thought, but couldn't we use the Null Object pattern (pp 365-369,
Patterns in Java Volume 1, Mark Grand) as a default for this scenario?

It would mean that there would be no further need to make an explicit test
for null, as calling the corresponding method will have no effect.

As I said, just a thought. In any case, keep up the brilliant work.


Cheers,
Philip Hart

> -----Original Message-----
> From: Craig R. McClanahan [mailto:Craig.McClanahan@eng.sun.com]
> Sent: 02 February 2001 17:42
> To: struts-user@jakarta.apache.org
> Subject: Re: can a ActionForm be ever null in Action class
>
>
> Anand Raman wrote:
>
> > Hi guys
> >
> > I noticed in the struts-example application a check to find whether the
> > ActionForm "form" passed to the perform method of Action class
> is null or
> > not.
> >
> > Is it really necesarry.. I am not able to come up with a situation like
> > this.. According my knowldge a ActionForm is always populated before the
> > perform method is called on the Action class..
> >
> > can anyone please enlighten this situation
> >
>
> It will be null if and only if you have not associated an input form with
> this action.  Otherwise, an ActionForm will have been created and
> populated
> if it didn't already exist.
>
> Now, of course, since I wrote the entire app in this case, I
> *know* that the
> configuration file is correct, and the null checks are not strictly
> necessary.  On the other hand, if I was writing actions and
> someone else was
> building struts-config.xml, I'd generally do a little defensive
> coding like
> this to protect myself from configuration file mistakes ...
>
> >
> > Thanks for ur time
> > Anand
>
> Craig
>
>
>


Re: can a ActionForm be ever null in Action class

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Anand Raman wrote:

> Hi guys
>
> I noticed in the struts-example application a check to find whether the
> ActionForm "form" passed to the perform method of Action class is null or
> not.
>
> Is it really necesarry.. I am not able to come up with a situation like
> this.. According my knowldge a ActionForm is always populated before the
> perform method is called on the Action class..
>
> can anyone please enlighten this situation
>

It will be null if and only if you have not associated an input form with
this action.  Otherwise, an ActionForm will have been created and populated
if it didn't already exist.

Now, of course, since I wrote the entire app in this case, I *know* that the
configuration file is correct, and the null checks are not strictly
necessary.  On the other hand, if I was writing actions and someone else was
building struts-config.xml, I'd generally do a little defensive coding like
this to protect myself from configuration file mistakes ...

>
> Thanks for ur time
> Anand

Craig