You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by meeboo <de...@gmail.com> on 2007/06/11 14:52:03 UTC

[S2] Design patterns

Hey all

How do you build up your Struts 2 applications architecture wise? Say for
instance that you have a User model object. Do you create an action class
(e.g. UserAction.java) for all User actions, or do you separate them into
UpdateUser.java/CreateUser.java etc...? We thought Struts 2 was a big mess
at first since it allows you to construct your web-tier in virtually any way
you want. But after a couple of weeks we started using a "pattern" where
each JSP page has its own java action class and all action classes inherit
from a superclass which implements SessionAware, ValidationAware and so
forth. Do you think this is a good approach? It's worked great for us so
far. 

Cheers!
-- 
View this message in context: http://www.nabble.com/-S2--Design-patterns-tf3901386.html#a11059979
Sent from the Struts - User mailing list archive at Nabble.com.


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


Fixing the roseindia tutorial

Posted by Session Mwamufiya <sm...@andrew.cmu.edu>.
Hi,

Has anyone used the helloworld tutorial at
http://www.roseindia.net/struts/struts2/struts-2-hello-world.shtml?  I like
the fact that it uses a build.xml file to compile the whole thing, but the
tutorial doesn't work as such:
- the index.html file is never changed from the original that comes with the
blank struts 2 war file; so when it comes time to testing the tutorial we
are left with a void.
- also the build file builds the classes folder and moves struts.xml under
the WEB-INF/src folder, whereas I thought that the classes folder had to be
under WEB-INF in order for the struts 2 framework to find it.

Please help me fix this if you can, so that I can get my project started
with a single build file that can be used with ant.  Or, if you know of
another link that has a working tutorial that uses a build.xml file.

Thanks,

Session A. Mwamufiya
Carnegie Mellon University
MBA | Tepper School of Business
MSE (software eng.) | School of Computer Science
T: (412) 508-5455 | semwamufiya@cmu.edu



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


Re: [S2] Design patterns

Posted by Sami Dalouche <sk...@free.fr>.
Hi,

I personally :

1] Do NOT use inheritance, besides ActionSupport that provides the basic
methods (getText, ..) to work with Struts2.

2] Group all methods of a form inside the same Action. Usually, I need
the same code to prepare the input and the validation of the form, so
why would I bother with inheritance and additional classes when I can
find two clean methods in the same class ?

3] Never ever put business logic (besides validation, that should belong
to the domain, but Struts2 doesn't provide any adapter for Hibernate
Validator, so I have to live with that for now) inside the Actions. The
Actions are just here to either query services/domain or create business
objects and save them.  (See Domain Driven Design recommendations for
more information)

4] I only implement SessioNAware, ValidationAware, and so on when I need
to. I do not want to clutter ALL my classes with useless stuff I only
use 10% of the time. Just KISS :)

Regards,
Sami Dalouche

On Mon, 2007-06-11 at 05:52 -0700, meeboo wrote:
> Hey all
> 
> How do you build up your Struts 2 applications architecture wise? Say for
> instance that you have a User model object. Do you create an action class
> (e.g. UserAction.java) for all User actions, or do you separate them into
> UpdateUser.java/CreateUser.java etc...? We thought Struts 2 was a big mess
> at first since it allows you to construct your web-tier in virtually any way
> you want. But after a couple of weeks we started using a "pattern" where
> each JSP page has its own java action class and all action classes inherit
> from a superclass which implements SessionAware, ValidationAware and so
> forth. Do you think this is a good approach? It's worked great for us so
> far. 
> 
> Cheers!


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


Re: [S2] Design patterns

Posted by Kyle Adams <ka...@gfs.com>.

meeboo wrote:
> 
> Do you create an action class (e.g. UserAction.java) for all User actions,
> or do you separate them into UpdateUser.java/CreateUser.java etc...?
> 

I am also interested in the community's thoughts on this question.

On one hand, having an action class for each use case tends to result in an
explosion of action classes in large apps.  Furthermore, articles like Ian
Roughley's "Migrating to Struts 2"
(http://www.infoq.com/articles/migrating-struts-2-part2) and the "Starting
Struts 2" book (page 70) seem to advocate for consolidating related actions
into on Action class with multiple methods.

On the other hand, Struts' zero config support doesn't seem to work unless
you keep the use cases separated out into separate Action classes.  I really
like zero config ;-)
-- 
View this message in context: http://www.nabble.com/-S2--Design-patterns-tf3901386.html#a11062286
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: [S2] Design patterns

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
I agree with Guru. After you've gained familiarity with S2, you need to 
consider about what's appropriate for the particular use-cases and 
business/domain model.
As soon as you start repeating yourself in your action/view code you 
know its time to refactor.

Here's some of my approaches:
- For CRUD, I'll generally follow the showcase example with one action 
for each 'root' domain object, with a different action method for each 
CRUD operation.
- If multiple related actions have the same behaviour or dependencies 
I'll create a superclass for those actions.
- I try to avoid having one superclass for all actions because they 
rarely all need common behaviour.  That can be convenient though.
- I try to avoid large numbers of getters and setters in the actions.  
It it gets out of hand I'll create an appropriate bean.
- Generally my actions relate to behaviour or specific business objects 
rather than "pages".  The ease-of-use of ajax divs and 'visitor' 
validation help this a lot.
- In some cases I create an S2 interceptor to inject dependencies based 
on my own *Aware interfaces. The Spring and Guice plugins work well. 
- As a strict rule the actions contain no business logic and know 
nothing of persistence.  Their role is fetch and manipulate data to/from 
the business/service layer for the view.

Hope that helps.
Jeromy Evans

Raghupathy, Gurumoorthy wrote:
> It all "Depends"........ 
>
>
> If the business logic for each operation (CRUD) is complex then better
> use 1 jsp  and one action.  
>
> Otherwise go for the other one (one class which handles all CRUD
> operations) ..... 
>
>
> However If you have designed and developed your business layer very well
> then either of the above should be fine ..... 
>
>
>
> Regards
>   
meeboo wrote:
> Hey all

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


RE: [S2] Design patterns

Posted by "Raghupathy, Gurumoorthy" <Gu...@nielsen.com>.
It all "Depends"........ 


If the business logic for each operation (CRUD) is complex then better
use 1 jsp  and one action.  

Otherwise go for the other one (one class which handles all CRUD
operations) ..... 


However If you have designed and developed your business layer very well
then either of the above should be fine ..... 



Regards




-----Original Message-----
From: meeboo [mailto:deepstar@gmail.com] 
Sent: 11 June 2007 13:52
To: user@struts.apache.org
Subject: [S2] Design patterns


Hey all

How do you build up your Struts 2 applications architecture wise? Say
for
instance that you have a User model object. Do you create an action
class
(e.g. UserAction.java) for all User actions, or do you separate them
into
UpdateUser.java/CreateUser.java etc...? We thought Struts 2 was a big
mess
at first since it allows you to construct your web-tier in virtually any
way
you want. But after a couple of weeks we started using a "pattern" where
each JSP page has its own java action class and all action classes
inherit
from a superclass which implements SessionAware, ValidationAware and so
forth. Do you think this is a good approach? It's worked great for us so
far. 

Cheers!
-- 
View this message in context:
http://www.nabble.com/-S2--Design-patterns-tf3901386.html#a11059979
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
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