You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ovidiu EFTIMIE <eo...@gmail.com> on 2005/06/14 23:19:25 UTC

Using ActioForm in ActionForm practice

Hi,
I've recently started working on a project that uses Struts 1.2 and
Hibernate - and I'm in the dev team. Nothing unusual here.
The project architecture is made in such way that ActionForms are an
almost 1-1 mirror with the the Hibernate mapped entities.
For example : if I have an entity A that contains an entity B and a
list of etities C, in the corresponding forms I'll have Aform
containing Bform and a List of CForm objects.

What I would like to know if anyone used the ActionForms in such a way
, or if this is considered to be a best practice.

Thanx,
Ovidiu

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


Re: Using ActioForm in ActionForm practice

Posted by Michael Jouravlev <jm...@gmail.com>.
Depends. This topic is discussed heavily from time to time. The last
tide was about a month ago :) Search archives.

Basically, if you need only to output your A, B, C entities, you do
not need action forms. Just stick your object in the proper scope.

If you need to input data into A, B, C or your A, B, C are interactive
(that is you need to output them, to modify them, to validate and to
redisplay them on error, and finally to store them back to hibernate)
then I know two obvious choices.

You must recall, that:
* Struts automatically stores request values into action form when
request hits the server.
* Also, action form is a bean, accessible from JSP. Thus, action form
can be used as a buffer for interactive I/O.
* Struts uses setters and getters to access properties.
* Struts does not try to set property, if request does not have
corresponding value.
* Simple redirect does not keep request values.
* Another thing to know, is that action form can handle aggregated
(aka nested) objects.
 
The choices I know of:

(1) Use action form as I/O buffer, business objects would contain only
valid and persisted data. Copy data from action form to BO when you
store data.
(2) Use a separate instance(s) of business object(s) or DTO(s) as I/O
buffer, and store all interactive data there, even invalid data. Valid
data can be persisted to database or wherever.

For (1) you would need to write a lot of setters/getters, but on the
plus side is that you do not need to call your business layer unless
all values are valid. You can check validity in validate() method. On
the other hand, if you already have validation functionality on
business layer, this does not look good.

For (2) You can aggregate your BOs in the action form. In this case
action form should have session scope. Struts would populate your BOs
as nested properties of action form. Less bloat in action form, but
your BOs need to accept strings, to validate input, and to store
whatever was set, even invalid data.

Are you going to handle Refresh button and double submits? After I
typed that huge email, I think I am entitled to a small plug :) Take a
look at DialogAction at
http://struts.sourceforge.net/strutsdialogs/dialogaction.html , maybe
you could use some its ideas.

Michael.

On 6/14/05, Ovidiu EFTIMIE <eo...@gmail.com> wrote:
> Hi,
> I've recently started working on a project that uses Struts 1.2 and
> Hibernate - and I'm in the dev team. Nothing unusual here.
> The project architecture is made in such way that ActionForms are an
> almost 1-1 mirror with the the Hibernate mapped entities.
> For example : if I have an entity A that contains an entity B and a
> list of etities C, in the corresponding forms I'll have Aform
> containing Bform and a List of CForm objects.
> 
> What I would like to know if anyone used the ActionForms in such a way
> , or if this is considered to be a best practice.

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


Re: Using ActioForm in ActionForm practice

Posted by Hubert Rabago <hr...@gmail.com>.
<shameless_plug>:  I hated the 1-1 mirroring of action forms and
business objects, so I wrote FormDef:  https://formdef.dev.java.net/ .
 You may want to take a look at it, it'll save you time keeping the
two in sync, and can also handle deep copying between the two,
especially the current dev version  (
https://formdef.dev.java.net/servlets/ReadMsg?list=users&msgNo=112
).</shameless_plug>

Hubert


On 6/14/05, Ovidiu EFTIMIE <eo...@gmail.com> wrote:
> Hi,
> I've recently started working on a project that uses Struts 1.2 and
> Hibernate - and I'm in the dev team. Nothing unusual here.
> The project architecture is made in such way that ActionForms are an
> almost 1-1 mirror with the the Hibernate mapped entities.
> For example : if I have an entity A that contains an entity B and a
> list of etities C, in the corresponding forms I'll have Aform
> containing Bform and a List of CForm objects.
> 
> What I would like to know if anyone used the ActionForms in such a way
> , or if this is considered to be a best practice.
> 
> Thanx,
> Ovidiu
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
>

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


Re: Using ActioForm in ActionForm practice

Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: "Ovidiu EFTIMIE" <eo...@gmail.com>
> The project architecture is made in such way that ActionForms are an
> almost 1-1 mirror with the the Hibernate mapped entities.
> For example : if I have an entity A that contains an entity B and a
> list of entities C, in the corresponding forms I'll have Aform
> containing Bform and a List of CForm objects.

It's that "almost" that will get you. :)  I have the same thing going on
with a near-1-to-1 mapping between Forms and DAO objects.  I use dynamic
forms, so at least I only write the get/set methods once in the data access
object.  (No Hibernate for me... non JDBC database.)

-- 
Wendy Smoak


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