Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts 1 Would ActionForm be Null

 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic