aspose file tools*
The moose likes Struts and the fly likes What are the features of Struts 2 which prompts someone to opt it as a framework? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "What are the features of Struts 2 which prompts someone to opt it as a framework?" Watch "What are the features of Struts 2 which prompts someone to opt it as a framework?" New topic
Author

What are the features of Struts 2 which prompts someone to opt it as a framework?

sumeet gupta
Ranch Hand

Joined: Aug 31, 2008
Posts: 33
Hi,
When we decide framework for our application , what are the features of Struts 2 which prompts someone to opt it as a framework for their Application.

Thanks,
Sumeet Gupta
Nishan Patel
Ranch Hand

Joined: Sep 07, 2008
Posts: 688

Hi,

With so many choices out there, why choose Struts2? Here are
some of the features that may lead you to consider Struts2:
Action based framework
Mature with a vibrant developer and user community
Annotation and XML configuration options
POJO-based actions that are easy to test
Spring, SiteMesh and Tiles integration
OGNL expression language integration
Themes based tag libraries and Ajax tags
Multiple view options (JSP, Freemarker, Velocity and
XSLT)
Plug-ins to extend and modify framework features


Action based frameworks came onto the scene to combine the
concepts of servlets and JSPs. The idea being to split the request
processing for the page the user sees into processing logic and
the presentation logic, letting each part do what it does the best.
The implementation used a pattern from Smalltalk known as the
model-view-controller pattern � or more recently known as the
front controller, or in Sun parlance Model 2.

As web applications became more complex, it was realized that
a page was no longer the logical separation � web applications
had multiple forms per page, links for content updates and many
other custom widgets � all which needed processing logic to
perform their tasks.

POJO Action's
● Struts 1
� Actions in Struts1 have dependencies on the
servlet API since the HttpServletRequest and
HttpServletResponse objects are passed to the
execute() method
● Struts 2
� Any java class with execute() method can be
used as an Action class.
� Actions to be neutral to the underlying framework
● ActionForms feature is no more known to the
Struts 2 framework.
● Simple JavaBean flavored actions are used to
put properties directly

Struts 1
● Action
● ActionForm
● ActionForward
● struts-config.xml
● ActionServlet
● RequestProcessor
● validation.xml

vs. Struts 2

● Action
● Action or POJO
● Result
● struts.xml
● FilterDispatcher
● Interceptors
● Action-validation.xml

Wildcard Default
● Using wildcards is another approach to
default actions.
● A wildcard action at the end of the
configuration can be used to catch
unmatched references.

<action name="*" >
<result>/{1}.jsp</result>
</action>

Pre-defined result names (tokens)
String SUCCESS = "success";
● String NONE = "none";
● String ERROR = "error";
● String INPUT = "input";
● String LOGIN = "login";

Interceptors
● Interceptors can execute code before and
after an Action is invoked.
● Most of the framework's core functionality is
implemented as Interceptors.
� Features like double-submit guards, type
conversion, object population, validation, file
upload, page preparation, and more, are all
implemented with the help of Interceptors.
● Each and every Interceptor is pluggable

Defining Validation Rules
● Per Action class:
� in a file named <ActionName>-validation.xml
● Per Action alias:
� in a file named <ActionName-alias>-validation.xml
● Inheritance hierarchy and interfaces
implemented by Action class
� Searches up the inheritance tree of the action to find
default validations for parent classes of the Action
and interfaces implemented

struts.xml
● The core configuration file for the framework
● Should reside on the classpath of the webapp
(generally /WEB-INF/classes).


Bundled Plug-in's
JSF plug-in
● REST plug-in
● Spring plug-in
● Tiles plug-in
● SiteGraph plug-in
● Sitemesh plug-in
● JasperReports plug-in
● JFreeChart plug-in
● Config Browser plug-in
● Struts 1 plug-in


Thanks,
Nishan Patel.


Thanks, Nishan Patel
SCJP 1.5, SCWCD 1.5, OCPJWSD Java Developer,My Blog
sumeet gupta
Ranch Hand

Joined: Aug 31, 2008
Posts: 33
Thanks Nishan for such a detailed response.Now I am very much clear with the features of Struts2.

Thanks,
Sumeet Gupta
Marcus Howarth
Ranch Hand

Joined: Jan 04, 2002
Posts: 37
Hi Nishan,

Firstly, thanks for above list, very comprehensive! (do I need the book now? )


Originally posted by Nishan Patel:


POJO-based actions that are easy to test

...

● Struts 2
� Any java class with execute() method can be
used as an Action class.
� Actions to be neutral to the underlying framework


do you go into the unit testing side of things in much depth in your book? I currently still use struts 1 and find the testing of actions gets so bogged down in mocks... well, its not so easy. Do you suggest using struts 2 means you could advocate TDD for action classes too?

thanks


Marcus<br /> <br />SCJP, March '02
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

do you go into the unit testing side of things in much depth in your book? I currently still use struts 1 and find the testing of actions gets so bogged down in mocks... well, its not so easy. Do you suggest using struts 2 means you could advocate TDD for action classes too?

There is a chapter covering testing from several angles: simple action testing, interceptor testing, full-stack action testing, and functional testing via driving a browser from unit test code.

The architecture of Struts 2 makes testing much, much easier than in Struts 1, IMO, and makes TDD much more feasible than with Struts 1.

Dave
Marcus Howarth
Ranch Hand

Joined: Jan 04, 2002
Posts: 37
Thanks Dave,

Having now read up on your book I see this is one of the main points listed!!
* "Apply the best of agile development techniques and TDD techniques"


It also says its a beginners guide and you need no javascript or css. Could you say who your target audience is? How much of the book is covering Struts 2.1 specifics as opposed to "interspersed with detours into more advanced development topics"?

Looks really good, sorry also for answering wrong thread assuming it was you
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

It also says its a beginners guide and you need no javascript or css.

Personally, I think knowing some JavaScript basics is important for the book--I cover some of the current JavaScript "best practices" but don't introduce JavaScript itself.
Could you say who your target audience is? How much of the book is covering Struts 2.1 specifics as opposed to "interspersed with detours into more advanced development topics"?

The first half of the book is largely Struts 2 and agile development methodology in parallel. The second half covers more web-oriented topics like JavaScript, some CSS, comprehensive testing, documentation, and so on.

The precise target audience is "people that need to get up to speed on good web development practices using S2 really quickly". More broadly, it covers a fair amount of advanced topics, but in a way that's accessible to less-experienced developers, but still useful to those that already know "everything" ;)

Dave
 
Consider Paul's rocket mass heater.
 
subject: What are the features of Struts 2 which prompts someone to opt it as a framework?