The first development build (2.0.1) of Apache Struts 2 project has been released.
Struts 2 was originally known as WebWork 2. After working independently for several years, the WebWork and Struts communities joined forces to create Struts 2. This new version of Struts is designed to be simpler to use and closer to how Struts was always meant to be. Some key changes are:
- Improved Design – All Struts 2 classes are based on interfaces. Core interfaces are HTTP independent.
- Intelligent Defaults – Most configuration elements have a default value that we can set and forget.
- Enhanced Results – Unlike ActionForwards, Struts 2 Results can actually help prepare the response.
- Enhanced Tags – Struts 2 tags don’t just output data, but provide stylesheet-driven markup, so that we can create consistent pages with less code.
- First-class AJAX support – The AJAX theme gives interactive applications a significant boost.
- Stateful Checkboxes – Struts 2 checkboxes do not require special handling for false values.
- QuickStart – Many changes can be made on the fly without restarting a web container.
- Easy-to-test Actions – Struts 2 Actions are HTTP independent and can be tested without resorting to mock objects.
- Easy-to-customize controller – Struts 1 lets us customize the request processor per module, Struts 2 lets us customize the request handling per action, if desired.
- Easy-to-tweak tags – Struts 2 tag markup can be altered by changing an underlying stylesheet. Individual tag markup can be changed by editing a FreeMarker template. No need to grok the taglib API! Both JSP and FreeMarker tags are fully supported.
- Easy cancel handling – The Struts 2 Cancel button can go directly to a different action.
- Easy Spring integration – Struts 2 Actions are Spring-aware. Just add Spring beans!
- Easy plugins – Struts 2 extensions can be added by dropping in a JAR. No manual configuration required!
- POJO forms – No more ActionForms! We can use any JavaBean we like or put properties directly on our Action classes. No need to use all String properties!
- POJO Actions – Any class can be used as an Action class. We don’t even have to implement an interface!
Struts 2 key features
- A flexible, plain old Java object (POJO)-based architecture to structure your code and pages, yet stay out of your way.
- A theme-enabled tag library supporting JSP, Velocity, and Freemarker.
- A simple plugin framework to integrate with third-party libraries like JavaServer Faces, JasperReports, and JFreeChart.
- Built-in debugging tools supporting profiling, problem reports, and interactive object model queries.
- Automatic portlet support allowing portal and servlet deployments with no code changes
- Quick start development tools like Maven archetypes, automatic reloading configuration files, and bootstrap tutorials.
After reading the great article Deploying BIRT from Jason Weathersby I decide to create a little example on how to use BIRT RE API with Apache Struts framework.
To do so I’ve followed Jason steps:
- Create a WebReport/WEB-INF/lib directory underneath the Tomcat webapps directory.
- Copy all the jars in the birt-runtime-2_5_2/ReportEngine/lib directory from the Report Engine download into your WebReport/WEB-INF/lib directory.
- Next, create a directory named platform in your WEB-INF folder.
- Copy the birt-runtime-2_5_2/Report Engine/plugins and birt-runtime-2_5_2/ReportEngine/configuration directories to the platform directory you just created. In this example the context is WebReport, so the folder structure is /webapps/WebReport/platform/plugins and webapps/WebReport/platform/configuration.
- Additionally, create directories below WebReport for image location and report location.
And used the same directory structure:
The example allows you to generate reports in HTML, PDF, and XLS formats. For the last one I’ve used Tribix XLS Emitter 2.5.2.
To install Tribix XLS emitter just copy both
org.uguess.birt.report.engine.emitter.xls_22.214.171.124107181644.jar files into your /webapps/WebReport/platform/plugins folder.
Continue reading Deploying BIRT Report Engine API with Apache Struts
In Unification: Struts Action and JSF, Don Brown show us how to use Struts Action 2 and JSF as one framework.
Struts Action 2, based on the WebWork 2.2 code, has builtin support for JSF, using an approach that smoothly combines both frameworks into one configuration file, one framework. Struts Action takes the familiar Action-based approach to page logic and navigation, and sprinkles in optional support for JSF components. The result is a framework that lets the developer easily incorporate component-driven pages as application needs dictate.
The JSF components still have access to the entire JSF lifecycle while retaining the action-based paradigm.
JSF/Struts Action configuration file example:
<action name="employee" class="org.apache.struts.action2.showcase.jsf.EmployeeAction">
<interceptor-ref name="basicStack" />
<interceptor-ref name="jsfStack" />
<result name="success" type="jsf" />
<result name="index" type="redirect-action">index</result>
Strecks, a set of open source extensions to the Struts framework aimed at Java 5 users, has been released. Strecks (which stands for “Struts Extensions”) is built on the existing Struts 1.2.x code base.
Read Phil Zoio’s article on Strecks, titled “Building on Struts for Java 5 Users”.
Strecks contains a range of features aimed to streamline the Struts programming model. Some key features include:
- POJO action beans with no framework dependencies
- action vs. controller separation. Request processing logic is encapsulated into Action controllers, simplifying action implementations
- annotation-based dependency injection (typed request parameters, session attributes, Spring beans, and others)
- annotation-based form validators (XML and code-free)
- annotation-based data binding from form properties to domain model
- annotations for additional per-field control over type conversion
- simplified mechanisms to support navigation and redirecting after posts
- pluggable navigation using annotations
- pre- and post-action interceptors, with access to dependency resolved action beans as well as full runtime context
For a more complete list, see http://strecks.sourceforge.net/features.php.
Struts is by far the most common web framework, but it is by no means the only option.
Java Server Faces has made a splash lately, but there are a number of open source alternatives, including Spring MVC, WebWork, Tapestry, and Cocoon.
I’ve found two interesting presentations that survey these available web frameworks, taking a look at what kind of code and content you need to write for each, specific strengths or weaknesses, and how to select the best web framework for your unique application requirements.
The second one takes even a closer look at how do these web frameworks work.