This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Struts and the fly likes Struts 1 Would ActionForm be Null Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 1 Would ActionForm be Null" Watch "Struts 1 Would ActionForm be Null" New topic

Struts 1 Would ActionForm be Null

Alec Lee
Ranch Hand

Joined: Jan 28, 2004
Posts: 569
It is common to see example Action class containing these:

But the point is, why check for a null form? Does that mean the Action class could receive a null ActionForm even under normal condition (assuming there is no error in the struts-config.xml and we've defined our ActionForm properly)? And what should we do if a null form is received?
Gayathri Chowduru
Ranch Hand

Joined: Oct 17, 2007
Posts: 42
It is not common to see if(form != null)....

I guess, If you define everything properly in struts-config.xml then, this if-condition is not needed. For example, if you try to print the form whether it is null or not, it will print the actionForm what ever you are passing in to the execute method.

Unless you do not intialize the ActionForm bean, it will not be null.

Thanks & Regards,
Gayathri Chowduru.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
There is only one condition that I know of that would cause the form to be null and that is if you don't define a name attribute in your action mapping. Since multiple action mappings could point to the same action class, it is conceivable that the form could be null under some circumstances and not null under others.

This is a very unusual situation, though. If you always define a name attribute for your actions, I wouldn't bother checking for a null form every time.

Consultant, Sima Solutions
I agree. Here's the link:
subject: Struts 1 Would ActionForm be Null
It's not a secret anymore!