This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Struts and the fly likes Struts2 Action best practice Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2 Action best practice" Watch "Struts2 Action best practice" New topic

Struts2 Action best practice

Kevin P Smith
Ranch Hand

Joined: Feb 18, 2005
Posts: 362

I was just wondering if someone could give me their views on the 'best practice' for struts2 when it comes to Actions.
I have been creating an app that currently uses a UserAction class; this contains all my methods for login, loginConfirm, register, registerConfirm, userProfile etc etc etc.

I was just wondering if it is considered 'right' to group all User actions in one class, or is I should be doing something like:-
UserLoginAction, UserregisterAction, UserProfileAction. Or does it really not matter.

Just really wondering if I'm heading down the right road, or straying away from Struts 'best practice'.

Cheers in advance
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Keep in mind that the Struts Framework Action class is a component of a Struts-based Controller (in MVC terms.) When programmers use Struts while building their applications, they add behavior to a Controller by creating customized Action classes and then configuring them with the other parts of the Controller that come with the Framework.

To summarize, custom Action classes, the pre-written Struts classes and an instance of struts-config.xml together are your Controller. You should not code customized business logic in Action classes, i.e. the Controller. This logic belongs in Model classes, not Controller classes.

A Presentation-tier Business Delegate is typically the mediator between a Controller and Model.
I agree. Here's the link:
subject: Struts2 Action best practice
It's not a secret anymore!