What about a class hierarchy such as:

ActionSupport
  BaseAction
    UserBaseAction
      UserCreateAction
      UserSaveAction

I've personally tried the other approach where you would
have something like:

ActionSupport
  BaseAction
    UserAction

Then you would use the method attribute on your struts 
action mapping to control a specific URL action to a 
specific method call in your action class. 

While the latter does cut down on the number of classes that
one must maintain, I find that the user action then becomes
bloated, particularly when you have a fair number of methods
maybe being called in that action, including your ajax 
callbacks, etc.  

The first hierarchy to me provides some level of discipline 
on where your view-level logic should be implemented.  

If its only specific to that single view, it goes in the 
leaf action.  If it's common to that specific collection 
of module calls, it goes in your functional base action.
But if its common across multiple functional areas, it
can be implemented in your application's base action.

The key to remember though is that you want to keep your 
action classes as bloat-free as possible.  Business 
logic is better placed in a service object rather than 
the action, reserving the action class purely for view 
level handlers only.

> -----Original Message-----
> From: adam pinder [mailto:apin...@hotmail.co.uk]
> Sent: Friday, September 24, 2010 10:31 AM
> To: user@struts.apache.org
> Subject: RE: How to structure a struts2 application
> 
> 
> 
> 
> one action per function or functional area is probably best.
> 
> 
> 
> you can then tailor the validation and responses more easily.
> 
> 
> 
> adam
> 
> 
> 
> > Date: Fri, 24 Sep 2010 10:35:42 +0100
> > Subject: How to structure a struts2 application
> > From: darrenkarst...@gmail.com
> > To: user@struts.apache.org
> >
> > Hi,
> > I have just started learning struts2 and was wondering what is the
> best way
> > to structure my application.
> >
> > I was planning on creating one ActionSupport class to deal with all
> user
> > action (creating, editing, login etc). This would have a method for
> each
> > type of action (create(), login() etc) and a mapping with a wildcard
> like
> > this:
> > <action name="*User" class="uk.co.javawebgames.UserAction"
> method="{1}">
> >
> > However im not sure if this is the best way of doing things because
> all of
> > the user actions would share the same validate method, and each
> different
> > type of action would need different validation. I was thinking of
> maybe
> > putting a switch in the validate method to do different validation
> depending
> > on which action has been called, or perhaps just having different
> action
> > classes for each type of user action. Do either of these approaches
> sound
> > sensible? Or am I missing an easier way to go about grouping up all
> the user
> > actions?
> > Regards
> > Darren
> 


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

Reply via email to