Hi Chamal,

The recommendation of not passing ActionForms to your business classes
stems from two thoughts...

First, by passing an ActionForm, you tie your business clases to Struts. 
Should you want to change to another framework later, your business
classes should be unaffected, therefore, passing POJOs to them is a better
idea.  This also makes unit testing them a little easier since you don't
have to manually construct an ActionForm during the test (this isn't such
a big deal with ActionForm, but imagine if it for some reason had a
reference to an HttpRequest object, then it would be more of a hassle).

Second, an ActionForm is, usually, used to repopulate an HTML form on a
page when an error occurs, or when a page is initially shown.  Since HTML
forms only deal in Strings, another recommendation you frequently hear is
to only have Strings in your ActionForms.  For example, if you have a
textbox in your HTML form for a user to enter a date, having a real Date
field in the ActionForm can lead to problems because of the conversions
that have to take place back and forth (and if I remember correctly, no
conversion is done when redisplaying the HTML form anyway, so you'll get
the default toString() of the Date object, which is almost certainly not
what you want).  If you instead make it a String field, the only
conversion is when you ultimately need to pass it to the business layer,
in which case you have more full control over it.  So, since you probably
want to be dealing with real Java data types in your business classes, but
an ActionForm was designed to deal with HTML forms and therefore only
Strings, trying to make an ActionForm serve both purposes can lead to
problems, so its easier to just avoid the situation altogether.

HTH,
Frank

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM: fzammetti
Yahoo: fzammetti
MSN: [EMAIL PROTECTED]
Java Web Parts -
http://javawebparts.sourceforge.net
Supplying the wheel, so you don't have to reinvent it!

On Thu, June 8, 2006 12:29 pm, chamal desilva wrote:
> Hi,
>
> I read few articles on struts. They recommend not to
> send action form class to EJBs as data holders. They
> recommend we should use general classes for holding
> data to decople web tier with EJBs.
>
> What they say must be correct but I still have few
> doubts (Maybe b'cause I am not experienced).
>
> Don't we have to modify two classes, if we use both
> ActionForms and normal java classes to store data.For
> example we will have modify two classes to add a new
> attribute, remove attribute etc.
>
> Please help me to understand this more clearly.
>
> Thanking You,
> Chamal.
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


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

Reply via email to