File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes why not pass ActionForm instance to Model 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 "why not pass ActionForm instance to Model" Watch "why not pass ActionForm instance to Model" New topic

why not pass ActionForm instance to Model

Vijay Raj
Ranch Hand

Joined: Oct 10, 2005
Posts: 110

Why shouldn't we pass ActionForm instances to the Model. I read somewhere that it causes high coupling. If true, so what.

I am not able to understand the practical dis-advantages of passing an ActionForm instance. What problems may it cause?

Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Here's a scenario that might help explain it:

Say you decide to ignore the advice and pass your ActionForms as parameters to your model classes. Everything will work great, all is well, life is good.


Your boss or client comes to you and says, "The CEO read in a airline magazine that JSF with AJAX is really the way to go, and Struts is really out of date. I want you to convert this application to JSF and Ajax."

You're thinking: OK, it's cool, I've used Model/View/Controller. I can just take the Model code that I've written and plug it into a JSF view.


Since you made your Model class dependent on a Struts class (org.apache.struts.action.ActionForm) as soon as you remove struts.jar from your project, the model classes will no longer compile. You now have the choice of leaving the struts.jar file in the project just to make the project compile, or change your model classes.

The moral of the story: Tightly coupling your model classes with Struts or any other view framework is a bad thing.
[ July 05, 2006: Message edited by: Merrill Higginson ]

Consultant, Sima Solutions
Timothy Sam
Ranch Hand

Joined: Sep 18, 2005
Posts: 751
OMG! I have my every model extend ActionForm and did something like...

public class Applicant
NameFormBean name;
ApplicationInfoFormBean applicationInfo;

where all those members extend ActionForm!!!

SCJP 1.5
I agree. Here's the link:
subject: why not pass ActionForm instance to Model
It's not a secret anymore!