struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject Re: question re. struts
Date Sun, 02 Feb 2003 23:19:34 GMT


On Sun, 2 Feb 2003, Sundar Narasimhan wrote:

> What I would have liked to be able to do is..
>
>         class PointForm extends Point implements SomeStrutsFormInterface {
>         }
>
> in cases where this is possible. The advantage of this is that it
> still maintains and allows for the *Form classes to be decoupled from
> the Model classes, but allows for "code" re-use.. I don't have to
> write several lines of repeated code.. or just spend a lot of time
> writeing to string and from string methods for every single
> attribute. In a language such as Java where no pointers exist taking
> the reflection overhead seems like a big waste -- and writing all
> these repeated methods seems such a productivity reducer :)
>
> Am I making sense?
>

The question about "why isn't ActionForm an interface" is one of the
largest producers of mail volume on STRUTS-USER in the almost-three-year
history of the mailing list.  You should really go back through some of
the archives to review the pro and con arguments; and (among other things)
you will find that I am adamantly against what you propose -- it would
encourage people to reuse the wrong thing for the wrong reasons.

What you really want to do is reuse business logic components and value
objects.  ActionForms are part of the view tier, and their design should
really be under the control of the page author, or whoever is determining
what properties go on the input form.  In addition, the data types in a
form bean should generally be strings, while model tier objects and value
objects should generally use the underlying native data types.

> If it does, what I'd like to know is what people do to reduce the
> amount of code.. is there a tool that can perhaps 'generate' the form
> given a model.. ? Or something.. I have tens of objects w/ hundreds of
> attributes and I'm overwhelmed w/ the amount of code Struts seems to
> imply.
>

There's certainly tools around for this purpose (like XDoclet), but I just
use Struts 1.1 out of the box.  DynaActionForm form beans let you
configure the properties of a form bean in struts-config.xml with no need
to actually create a form bean class at all, unless you need a custom
reset() or validate() method.  And, even then, those are the only methods
you need to implement -- not all the property getters and setters.

Also, dynamic forms work just fine with the validator framework as well,
so it's getting more uncommon to have to write a real form bean class any
more ...

> Thanks.

Craig McClanahan

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message