Editor's Note: This is part one of a two-part article on Jakarta Struts 1.1. Portions of this article are excerpted from Sue Spielman's book, The Struts Framework: Practical Guide for Java Programmers (Morgan-Kaufmann), one of the first books on the market covering Struts 1.1 in detail. You can reach Sue at .
Over the last year, the Struts framework, a Jakarta open source project, has become practically the de facto standard for building Web applications. Based on the MVC architecture, Struts has proven to be a solid framework that can be used on systems of all sizes. In fact, Iíd be hard-pressed to come up with a reason why you and your development team should spend cycles developing a custom MVC framework for a project. It just doesnít make sense.
Struts v1.1 is the latest version of the framework. While in beta 2 at the time of this writing, it should shortly be in final release. There is no reason, however, why you canít start using v1.1 today; in fact there are many reasons why you should.
There are two parts to this article. In this first part, we'll cover integration of Jakarta common libraries and multiple application support. The second part will hit the nested tag library, the plug-in API, and declarative exception handling. There have been some significant improvements to the framework, and chances are that youíll want to start new development with this release. In fact, I would highly recommend doing just that. It has always been a goal of the committers on the Struts project to maintain backwards compatibility with v1.0.2, and they have done an excellent job in the v1.1 release. The last section of this article will point out some things to consider if you're upgrading from v1.0.2 applications to v1.1.
This article is not a Struts primer. It assumes you are familiar with the various components in the architecture. If you need a primer, visit my three-part introduction to the Struts framework.
There have been some exciting features and improvements made to Struts over the course of the v1.1 development. Weíll talk about each of these in turn, but letís see what is on the plate.
- Use of Jakarta Commons libraries, such as
DynaActionForms for creating dynamic action forms that do not require any coding
- Multiple application support for allowing multiple struts-config.xml files to be defined
- Nested Tag Library for allowing a nested object hierarchy to be easily accessed from JSP pages
- Tiles and Validator for providing advanced templating and form validation expressions.
- Plugin API for
- Declarative exception handling that allows
Actionsto not have to worry about catching all exceptions
Letís look at each feature in turn.
Integration of Jakarta Commons libraries
The Struts utilities package helped solve problems that pop up over and over when building Web applications. Most of the classes in this package do not rely on the controller Servlet framework or the custom tag libraries, so they can be used in general Java application programming. As of Struts 1.1, many of the classes in this package were moved into the Jakarta Commons project. These include the Bean Utilities, Collections, and Digester packages. The logging provided in Struts actually comes from the Commons project as well.
org.apache.commons.beanutils components provide wrappers around the Java Reflection and Introspection APIs. By using classes in the
Beanutils package, it is possible to access getter and setter methods dynamically without compiled-in knowledge of the method names. These classes are used with the custom tag libraries of Struts, so it makes sense that if you are writing additional custom tags for your application, you might want to look further into what is available in this package. Table 1 gives you a sense of what is available.
Table 1. Commons Packages Used in Struts 1.1
||Populates JavaBeans properties via reflection.|
||Converts String values to objects of the specified class.|
||Describes one mapped property.|
||Focuses on methods in general rather than properties in particular.|
||Uses Java Reflection APIs to allow for generic property getter and setter operations.|
Digester package provides rules-based processing of XML documents. This is great for reading configuration files so that Objects can be initialized correctly. What makes this package useful is that you can do many of the things fairly simply that would otherwise require more in-depth knowledge of DOM or SAX processing. This is accomplished by having a Java object-mapping module that allows specifying rules when patterns in the XML are recognized. There are a number of advanced features available when using a Digester. These include the ability to plug in your own pattern-matching engine, namespace-aware processing, and the creation of
RuleSets that encapsulate Rules to be used in multiple applications. If you are explicitly reading any XML files into your applications and need to map them to the appropriate Java Objects, the Digester is quite useful.
Pages: 1, 2