Building on Struts for Java 5 Users
Struts is undoubtedly the most successful Java web development framework. It is the first widely adopted Model View Controller (MVC) framework, and has proven itself in thousands of projects. Struts was ground-breaking when it was introduced, but the web development landscape has changed a lot in the last few years. It is also fair to say that Struts is not universally popular, and has in many ways been overtaken by other frameworks.
Strecks is built on the existing Struts 1.2 code base, adding a range of productivity enhancing features, including:
How to Create Secure Web Applications with Struts
This article will focus on developing secure Web applications with the popular Java framework Struts. It will detail a set of best practices using the included security mechanisms. The first section will provide an overview of both Struts and Web application security as a context for discussion. Each subsequent section will focus on a specific security principle and discuss how Struts can be leveraged to address it.
Struts is a very popular framework for Java Web applications large and small because of the numerous advantages it offers developers. The main goal of the Struts framework is to enforce a MVC-style (Model-View-Controller) architecture, which means that there is a separation of concerns among different architectural components: the model is the representation of the logic, the view is in charge of displaying data to the user, and the controller is responsible for providing the user with a way to interact with the application and affect the model. A simple analogy for this is a video game, where you have a game console (the model), the television or monitor (the view), and a controller (quite appropriately, the controller). This architectural pattern promotes reuse and stability by reducing the effects of code changes (since the implementation of each component is agnostic to the implementation of the others and the model is isolated from the user).
Bridge the gap between Struts and Hibernate
Hibernate and Struts are currently among the most popular open source libraries on the market. Effectively, they are the default developer selections among competing libraries when building Java enterprise applications. Although they are often used in conjunction with one another, Hibernate was not primarily designed to be used with Struts, and Struts was released years before the birth of Hibernate. To put them to work together, some challenges remain. This article identifies some of the gaps between Struts and Hibernate, particularly related to object-oriented modeling. It also describes a solution for bridging these gaps that involves an extension to the Struts framework. All Web applications built upon Struts and Hibernate can derive benefit from this generic extension.
Scheduling Jobs in a Java Web Application
There is a robust open source solution that works like a charm to standardize the way you conduct scheduling in a web application (or any other Java application, for that matter). The following examples will show you how to use Quartz, an open source scheduling library, to create a scheduling framework in your web application. The example also uses Struts Action framework plugins in order to initialize the scheduling mechanism when the web application starts. The Struts Action framework (or just "Struts") is a such a common framework that it should be familiar for most developers. Of course, there are many other frameworks available for Java web applications that facilitate a Model-View-Controller design pattern.
The first thing we want to do is set up the Struts plugin to create our scheduler when the container starts. For these examples, it is assumed that Tomcat will be the web application container of choice, but the examples should work in any container. We will create a Struts plugin class and add some lines to the struts-config.xml file to get this going.
Development Standards in Apache Struts
Apache Struts is a great framework for developing the front-end of Web applications. With smaller apps, it's hardly worthwhile to setup precise standards for how to define action classes and flow. However, the issue of standardization becomes more important as an application grows more complex. This is especially true when there are more developers on a team?then standardization becomes crucial. Most of the functionality in Struts can be implemented in many ways using Struts and having many developers working on the same project without standards will inevitable lead to an non-homogeneous and difficult to maintain system.
If you're an experienced Struts developer looking for ways to standardize a Struts application architecture, this article offers several pieces of advice to help improve development speed and the quality of your applications.
Struts Validations Framework Using AJAX
This article is concerned with enriching the existing struts validation framework with AJAX. A few components, such as a controller, have to be developed to select the validation framework and render the specific format message for the client side and a taglib to handle the error message rendering.
Developing JSR168 Struts portlets: Part 2. Enhancing the portlet
The first part of this article series showed developers who are familiar with the Struts framework in the servlet environment how to use Struts in the WebSphere Portal environment. We created a simple portlet application and then applied features of the Tiles and Validation frameworks to the application. In this part, we look at some portlet specific features provided by the IBM Struts Portlet Framework 22.214.171.124 (hereafter called the framework).
Portlets differ from servlets in several ways so the framework includes support beyond the servlet Struts framework. In Part 1, we talked about how it supports additional request processing requirements using the IViewCommand interface. Now you look at some of the additional support provided by the framework; specifically, you see how to use support for modes, devices, internationalization, and creating URLs, as well as how to integrate with the property broker so you can use cooperative portlet capabilities (a capability not yet available through the JSR 168 API).
An Exception Handling Framework for J2EE Applications
In most Java projects, a large percentage of the code is boilerplate code. Exception handling comes under this category. Even though the business logic may be just three or four lines of code, exception handling might go on for ten to 20 lines. This article talks about how to keep exception handling simple and straightforward, keeping the developer's plate clean for him to concentrate on business logic rather than devoting time to writing exception-handling boilerplate code. It also gives the basis and guidelines to create and deal with exceptions in the J2EE environment and targets some of the business problems, in which exceptions could be used to resolve them. This article uses the Struts framework as the presentation implementation, though the approach is applicable to any presentation implementation.
Developing JSR168 Struts portlets: Part 1. Creating a simple portlet
This article steps you through how to develop a simple JSR 168 compliant Struts portlet. You discover how request processing differs in the portlet Struts environment from the servlet Struts environment. You also see how to use the IViewCommand interface, and how to use popular Struts features, such as the Validation Plug-In and Tiles Plug-In, to enhance the basic portlet.
This article is not intended to be an introduction to either Struts or JSR 168. It assumes you have some experience using Struts in a Servlet environment and that you want to take advantage of this knowledge in a portlet environment. It can also be of interest to developers who already know how to use Struts to develop IBM Portal API compliant portlets. If you are new to either Struts or portlet technology, then please take a look at the Resources section for links to references which can help you get that background.
How to Make Struts People Happy with JSF
As a big promoter of JSF, I have been doomed to deal with many people, who have previous Struts experience. I notice in many cases that some sort of ?paradigm mismatch? exists between Struts and JSF. I call this the ?problem of the locomotive and the train.? Basically, this is a question of where to put the train engine ? at the head or at the end of the train.
The usual sequence of events looks like this:
1. Struts Servlet receives the call for ?/show-me-something.do?, recognizing the call based on the action mapping definitions in the struts-config file.
2. Servlet creates (or reuses existing) Form Bean.
3. Servlet calls the appropriate Struts Action execute() method, passing a Form bean among the parameters.
4. A Struts Action does the job, may be calling some other tiers of the Application Stack, maybe filling a Form Bean with some useful data.
5. The Struts Action returns a specific strongly-typed Action Mapping instance to let the Servlet know what page has to be rendered
6. The Servlet calls forward() to render that Page
7. During rendering, the Page can access some data in a Form Bean using special tag libraries (usually ether Struts, or JSTL)
Open Source-Based Portal-Lite
In the case of building a Proof Of Concept (POC) for a portal, you can solve all of the above by using the Open Source Apache Struts running on Jakarta Tomcat. With only a few lines of code and minor modifications, you can build a demo portal that can be run on a laptop by anyone who knows how to click an icon.
The key to the POC portal is in leveraging Struts Tiles. Portals are, in essence, a set of consistent layouts with different components. Struts Tiles are a continuation (seems like a replacement, now) of Struts Templates. Tiles leverage the JSP include feature to facilitate the reuse of presentation components in a consistent manner. Having built many portals as a consultant, the first time I saw a Tiles example (in someone else's online article for which I have lost the URL), I thought, "That is a portal."
Succeeding with Struts: Dynamically Allocated Forms
The peril of ending an article with a item left as a problem for the reader is that it inevitably comes back to haunt you. In my last article, Succeeding With Struts: Dynamically Sized Forms, I mentioned casually that it was possible to set up a form with indexed properties such that it could have a dynamically initialized array of values that varied depending on the number of items submitted. And, of course, I've gotten a ton of letters since then asking exactly how to go about it.
The classic example of this type of problem is a checkout form for a shopping cart. The action that displays the form knows exactly how many items are in the cart, and therefore can create the appropriate size array to service the page. But what happens when you submit? Remember that form populate happens very early in the Struts request processor, before validation or action processing. Even if you wrote a magic hidden field with the number of lines on the page, how could you get the array allocated before the form was populated, because the action runs after the form is populated? The answer lies in the one thing that does run before form population, the reset method for the ActionForm.
Support Eastern Languages in Your Struts Web Applications
Many Web development frameworks provide i18n support for this purpose. The Struts framework, one of the most commonly used, is no exception. Struts provides a set of classes and JSP tags that make it easier to work with i18n. This infrastructure enables Struts developers to produce multi-language applications with minimal extra effort and time.
Despite Struts' excellent i18n support, however, Struts applications that need to use Eastern languages such as Arabic require special attention and extra work. This article demonstrates how to build a Struts Web application that runs in English and Arabic. You will see how to set the user locale in Struts Action classes, set the appropriate HTML page direction, select the appropriate Cascade Style Sheet (CSS) file, and convert properties files so that Arabic characters are displayed correctly.
Dynamic radio buttons with Struts
This recipe follows on the heels of what you learned in my last article, "Dynamic checkboxes with Struts." Like dynamic checkboxes, radio buttons with dynamically selected elements can add a lot of sophistication to your Web pages, and with Struts, they're also easy to create.
In this article, I show you how to create a radio button group by nesting the Struts tags <logic:iterate/> and <html:radio/>. I then reference a specified form bean to the tags and iterate through a String array of radio button values, assigning an identical name attribute to each assigned value attribute.
What Is Struts
Apache Struts is an open source Java framework used for building web applications based on the servlet and JavaServer Pages (JSP) technologies. Is it conceivable that anyone in the business of building software hasn't heard of the Struts framework? From developers that are just starting out in the business to those long in the tooth, the name "Struts" surely must ring a bell. But if you haven't spent your development time in the Java world or haven't had the need to build web applications, Struts might only be a buzzword that you've added to your resume. For the next five to ten minutes, you're going to be taken on a whirlwind tour of the Struts framework. Get a drink (non-alcoholic, of course), sit back, and put your feet up, and learn a little about one of the most popular free frameworks to ever grace the open source community.
Build extra secure Web applications
You can easily integrate the protection framework with the Struts tag library so that the framework implementation is transparent. To integrate the framework into Struts, you must inherit the Struts tag libraries.
To protect form action and hidden fields, you modify Struts' FormTag and HiddenTag to invoke the Processor. Create a subclass that:
1. Extends Struts HiddenTag class; collects all hidden field parameters and stores them into the pageContext attribute.
2. Extends Struts FormTag class; overrides doAfterBody method to register the pageContext attribute and form action with Processor. The returned reference code outputs as a hidden field.
Sprinkle Some AJAX Magic in Your Struts Web Application
AJAX is the latest revolution in web development circles, allowing rich dynamic interfaces deployed within a normal web browser. Struts has been one of the de facto standards for Java-Web development for a number of years, with a large number of applications already deployed. This article will show you how to combine the richness of an AJAX user interface with your existing Struts applications.
The chances are that if you are reading this article, then you are interested in AJAX's ability to create dynamic web interfaces and would like to know how to add it to a Struts application. What are your options if you want to do this?
1. Wait until the next version of Struts (Shale) incorporates AJAX techniques. For Struts developers starting a new application this is probably the best option. The downside is that this will probably require moving to JavaServer Faces--not a bad thing in itself, but this may entail fundamental changes if you have an existing application.
2. You could move to a new approach, like Direct Web Remoting (DWR) or Ruby on Rails, which are specifically built for AJAX applications. While these are both very impressive frameworks, and are worth taking a look at if you wish to consider web development without Struts, this option would mean rewriting your entire application.
3. Add AJAX to your existing Struts application. Since AJAX is a technique, not a framework, it is straightforward to add it to Struts. For existing applications where stability (e.g., keeping existing libraries) is important, this option is recommended and is the one we explore in more detail.
Test-Driven Development Using StrutsTestCase
StrutsTestCase is a powerful and easy-to-use testing framework for Struts actions. Using Struts and then StrutsTestCase, in combination with traditional JUnit tests, will give you a very high level of test coverage and increase your product reliability accordingly.
StrutsTestCase is a test framework based on JUnit for testing Struts actions. If you use Struts, it can provide an easy and efficient manner for testing the Struts action classes of your application. The StrutsTestCase project provides a flexible and convenient way to test Struts actions from within the JUnit framework. It lets you do white-box testing on your Struts actions by setting up request parameters and checking the resulting Request or Session state after the action has been called.
StrutsTestCase allows either a mock-testing approach, where the framework simulates the web server container, or an in-container approach, where the Cactus framework is used to run the tests from within the server container (for example, Tomcat). In general, I prefer the mock-testing approach because it is more lightweight and runs faster, and thus allows a tighter development cycle.
Dynamic checkboxes with Struts
In user interface design, the checkbox group isn't as popular as its cousin, the multi-line selectbox. They both basically do the same thing; that is, they choose a collection of options mapped to a single name attribute. When used in groups, checkboxes actually perform the same function as the multi-line selectboxes, but they take up a little more screen real estate. This can be beneficial when you want the user to be able to view all the choices before selecting one or several of them.
While the multi-line selectbox typically provides a better look and feel when the choices are limited, a group of checkboxes is the better choice for any enterprise application where selection boxes must be rendered dynamically and contain preselection functionality. Fortunately, creating a group of dynamic checkboxes is easy to do with the Struts framework.
Get a better handle on Struts actions, with Spring
Like Struts, Spring can also function as an MVC implementation. Both frameworks have their merits and drawbacks, although most would agree that Struts is still king when it comes to MVC. Many development teams have learned to rely on Struts as the foundation for building quality software under strict deadlines. With so much momentum behind Struts, even development teams that would like to integrate features of the Spring framework don't want to switch to Spring MVC. The good news is that you don't have to. The Spring architecture allows you to connect Struts as your Web framework to Spring-based business and persistence layers. The end result is that you can have your cake and eat it too!
In the recipes that follow, you'll learn three ways to integrate Struts MVC into the Spring framework. I'll expose the cons of each recipe as well as its comparative advantages. Once you've seen all three in action, I'll show you an exciting application of the approach I like best.
Apache Struts Framework: The Big Picture
In this article, I will describe how to work with Struts, go over its main features, and discuss setting it up in an enterprise development environment.
The Struts framework is an open-source product for building Web applications based on the model-view-controller (MVC) design paradigm. It uses and extends the Java Servlet API and was originally created by Craig McClanahan. Please note: Because of the extensiveness of the Struts framework, there are entire books written just about it. It will be impossible to describe all the features of the framework in the constraints of this article. However, I will talk about the most important aspects of the framework. Also, I am assuming that you are familiar with some enterprise Integrated Development Environment (IDE), such as JBuilder 2005 or Eclipse and know how to create a Web application with it.
In this article, I'll show you how to integrate and use the Velocity Template Engine in your Struts applications. I'll give you the formula up front and then walk you through it, step-by-step. The resulting application will be one that combines Struts and Velocity -- a stellar combination that just might make you question your loyalty to JSP!
The recipe for combining Struts and the Velocity Template Engine is simple and straightforward; in fact, you can do it in just five steps:-
1. Place the Velocity JARs in your classpath.
2. Modify the web.xml file to recognize the Velocity servlet.
3. Place the Velocity toolbox.xml under your application's WEB-INF directory.
4. Modify your struts-config to point its views to Velocity templates instead of JSPs.
5. Create a Velocity template for each page you want to render.
Spring Your Struts Apps Ahead: The Struts-to-Spring Migration
This article helps developers who want to migrate their Struts applications to Spring MVC understand the logical mapping between the two frameworks and how to transform Struts applications into Spring MVC applications. Application developers with good Struts skills also will learn how key Struts concepts relate to Spring MVC concepts. Finally, this article should help architects understand and estimate the migration paths from Struts to Spring. To fully appreciate the subjects discussed, readers should have a working knowledge of the Struts framework.
The article is divided into two main parts:-
1. Logical mapping between the basic concepts of the Struts and Spring MVC frameworks
2. Essential recommendations for migration alternatives
Data Retention in JSPs using Struts
This article is intended for developers who have some working knowledge in the struts framework. The content of the whole article is purely based on what we have learned from our work experience.
Retaining data is one of the typical problems that a developer faces even after working in web applications for a considerable amount of time. Mostly we face such problem when some validation error happens through jsp, or user is submitting to the same jsp (or action path). The complexity lies in the fact that all of the fields that we need to retain are in the jsps, whether it is an array of html fields or just simple html fields.
Upload Files with Struts, Store Them with Hibernate
This article explains all the bottlenecks involved in this task and provides functional, easy code, which you will be able to use in your own projects. Struts 1.2.4 is used as the framework for building Java Web applications and Hibernate 3.0 (RC1) is used as the object/relational persistence and query service.
The article was written using Windows. On other operation systems, everything should run with only minor changes (if any at all).
Familiarity with BEA WebLogic server and of course with developing J2EE applications using Struts and Hibernate is necessary.
NetUI Page Flows: An Evolution of Struts
Struts is a popular framework used to build enterprise-level J2EE applications. With Struts, J2EE Web application development has become easier and more manageable. Beehive, an open-source project by the Apache Software Foundation, goes to great lengths to make Web application development even more straightforward by building a simple Page Flow model on top of Struts. Using the new JSR-175 and JSR-181 metadata annotation facilities, Beehive reduces the coding necessary for J2EE application development. This article introduces the Beehive Page Flow technology, and looks at how you can use it to increase the productivity and quality of Struts software. It also examines how you can migrate to include this technology in a vanilla Struts application. The article assumes you have some familiarity with Struts.
First Steps With Jakarta Struts, Part 2
Last time we looked at Jakarta Struts, I explained the persistence and business object layers and we wrote code to retrieve the list of topics from the database and represent them as objects. We used a Struts ActionMapping and an ActionForward, to get as far as the JSP that will actually display the topics on the screen.
Improve performance by caching Struts and Tiles applications
Struts is an open source framework for building Web applications based on the model-view-controller (MVC) architecture. The Struts framework provides its own controller component and integrates with other technologies to provide the model and the view. The primary focus of this framework is to provide a control layer for the Web application, reducing both construction time and maintenance costs.
The Tiles framework builds on the jsp:include feature of Java? Server Pages (JSP) architecture, and comes bundled with the Struts Web application framework. This framework helps to reduce the duplication between JSP files, as well as make layouts flexible and easy to maintain. The Tiles structure provides a full-featured, robust framework for assembling presentation pages from component parts.
Create an XML Web Application with Struts, Xerces, and Xalan
Despite XML's ubiquity, it's not always obvious how to use it in a Web application?or why you would want to in the first place. This article answers both questions, explaining why and how to build a simple XML-oriented Web applicationIt will help for you to already be familiar with XML, Java's XML API, and of course, with creating of J2EE Web applications using the Jakarta Struts framework. However, even if you're not proficient with the above-mentioned tools, this article can certainly serve as your starting point.
For your Web container, you can use any J2EE compliant server?this article uses JBoss 3.2.6. To build the Web application, use the open source framework Jakarta Struts 1.2.4. For XML/XSLT processing, you'll need Apache Xalan 2.6.0, which is an XSLT processor for transforming XML documents into HTML, text, or other XML document types. To create XML documents, you'll need Apache Xerces2, but you do not need to download and install it separately, since it's included in Xalan's package. To compile, pack, and deploy, you'll need the Apache Ant 1.6.2 build tool.
First Steps with Jakarta Struts
this article isn't an attempt to provide a definitive source of documentation. Rather, it's intended to allow Struts newcomers to hit the ground running, to get a feel for what the framework is like, and understand what it can and can't do.
Of the Struts example applications I've seen, most have been either too trivial or too complex, the complex ones having lots of external dependencies that must be resolved before the example can even be compiled and run. In this tutorial, I'll attempt to hit a spot between these two extremes. I've deliberately created an application that has the minimum of external dependencies, so you should be able to actually run the code without too much difficulty! Everything you'll need is open-source and can be downloaded for free -- one of the advantages of J2EE.
Web Wizard Component, Part 2: The View
I will show how to create the wizard user interface using the Struts framework. I chose it primarily because I've used it for quite a while, and I know it well. Struts is widely adopted by the Java community, so the source code should be easy to understand. I also believe that front controller paradigm, used in Struts and the like, allows for better exploitation of the underlying HTTP protocol. On the other hand, most of the code is Struts-agnostic, and can be ported to other frameworks with a similar programming model.
The complete wizard will contain the following components:-
1. The Rule Container, which consists of the wizard controller, nodes, and edges. We designed this component in the previous article.
2. Three wizard pages, corresponding to the three nodes of the Rule Container.
3. Two stub pages, which are used when the Rule Container is not initialized.
4. The UI controller, defined by Struts' action class/form bean classes.
Web Wizard Component, Part 1: The Model
This article makes another approach to complex control elements for the Web, and shows how to implement a wizard control using the good old <form> element on the client side and a set of navigation rules on the server side. The navigation rules are fully detached from the user interface, providing better code reuse and allowing the testing of wizard rules programmatically.
A wizard is a UI component, designed to input data in portions step by step. A wizard usually has the following qualities:
1. All wizard data compose a single transaction.
2. Steps are processed in sequence from beginning to end.
3. There is one starting step, several intermediate steps, and one ending step.
4. The wizard validates its state before advancing to the next step.
5. There can be several different paths to reach the ending step.
6. It is possible to navigate back to review and update values entered in previous steps.
7. A wizard can be cancelled before completion.
Audit Your Struts Configuration Files to Avoid JAAS Errors
The Struts Web application framework facilitates building robust Web applications. Java Authentication and Authorization Services (JAAS) is a rich API for adding pluggable security modules to applications. These powerful services work well together, however, their combination can also add some complexity to maintenance and enhancement tasks. Maintaining synchronization between an application's Struts configuration file(s) mappings and the JAAS security framework policy file can be a challenge.
The Struts configuration files are XML and the JAAS policy file is a structured text file, therefore, they can be parsed and processed in an automated fashion. This article describes an audit utility that iterates over the XML configuration files in a given directory, parses the <path> element and then verifies that the path element data (the page file name) appears in the JAAS policy file. This article walks you through the Python code for the utility so you'll be able to customize it for your environment. The article doesn't discuss how to use Struts or JAAS; if you're not familiar with these technologies you should explore the resource links listed in the left column of this article.
The Best of Both Worlds: Integrating JSF with Struts in Your J2EE Applications
Struts has been a popular and widely used framework for building web applications using Java. Recently, a new API that has significant overlap with Struts functionality?JavaServer Faces (JSF)?has become standard, giving rise to questions about which technology developers should use, and what they can do with existing Struts-based applications to start taking advantage of JSF's capabilities. This article briefly introduces both technologies, and discusses how to migrate the user-interface elements from Struts to JSF, providing a technique you can use to integrate the two technologies to obtain the best of both worlds.
The Struts Framework is a very popular framework for building web applications in Java. Its key features include:
1. An overall architecture based on Model-View-Controller (MVC) design principles in which all requests get funneled through a controller that exerts overall management and dispatches requests to appropriate application components as needed, based on logical identifiers that reduce coupling between tiers.
2. Form-management capabilities, such as the ActionForm JavaBean that represents the server side state of the input fields on a form, and a validation framework externaliz the configuration of the set of correctness checks to be applied to input field values, plus implement those checks on both the client side and the server side.
3. The Tiles framework for layout management, which supports creation of sophisticated layout templates that can be reused across multiple pages, and thus allows easy modifications to the overall look and feel of an application.
4. A set of JSP custom tags that can simplify the process of creating the application's HTML markup for the view tier of your application, and which works in a synergistic way with the form management capabilities and the overall controller architecture.
Struts action mappings: Divide Et Impera
This article discusses different combinations of a Struts action class and a form bean and how these combinations can be used.
Full action call sequence
1. Struts controller component receives a request.
2. Struts identifies the action mapping which is responsible for request processing.
3. Struts creates a new instance of the form bean, if it was not found in the scope or if the scope has "request" type. If the bean exists in the scope, it is reused.
4. If form bean defines reset() method, it is called (1)
5. Struts populates the fields with request arguments, using mutators (2)
6. Struts calls validate() method if "validate" attribute of action mapping is not set to "false" (3)
7. If validate() returns non-empty ActionErrors object, control is forwarded to an URI identified by "input" attribute of the action mapping (4a)
8. if validate() returns empty ActionErrors object or null, Struts calls execute() method of the action class (4b)
9. execute() method returns an ActionForward object, which is used by Struts to select the destination URI (5)
Struts Best Practices
Struts is a popular Web presentation framework that has garnered considerable community support. This article aims to highlight some best practices that can be applied in medium to large projects to aid efficient development and low-maintenance quality code. In the course of this article we shall explore ways to optimize the design and development of Struts-based applications.
Struts, a Jakarta project hosted by Apache, is a framework for building Web applications based on the MVC2 design pattern. The framework, built upon standard technologies like Java Servlets, JavaBeans, ResourceBundles, and XML, aims to provide an extensible Web application architecture that the development team can build on. The use of Struts enforces modularity and separation of concern, increases code manageablity, extensibility, and consistency.
Error validation and exception handling in portlets, using the Struts Portlet Framework
Having a good design and implementation for error validation and exception handling enables applications to respond gracefully in abnormal conditions. This article tells how you can leverage error validation and exception handling features, which are built into the WebSphere Portal Struts Portlet Framework, in your portlet applications.
Most portlet applications accept input from users. The input can come in many forms, such as input text fields, dropdown lists, radio buttons, or check boxes. Sometimes users do not provide appropriate input. An application might expect specific date and phone number formats, require certain input fields, and need other specific forms of data. Therefore, the application needs to validate the input.
In this article, we will use a sample Struts application to demonstrate how to extend Struts using each of these three approaches. Downloadable sample code for each is available below in the Resources section at the end of this article. Two of the most successful examples of Struts extensions are the Struts Validation framework and the Tiles framework.
Struts is not only a very powerful framework, but also very extensible. You can extend Struts in three ways:
1. PlugIn: Create your own PlugIn class if you want to execute some business logic at application startup or shutdown.
2. RequestProcessor: Create your own RequestProcessor if you want to execute some business logic at a particular point during the request-processing phase. For example, you might extend RequestProcessor to check that the user is logged in and he has one of the roles to execute a particular action before executing every request.
3. ActionServlet: You can extend the ActionServlet class if you want to execute your business logic at either application startup or shutdown, or during request processing. But you should use it only in cases where neither PlugIn nor RequestProcessor is able to fulfill your requirement.
JavaServer Faces (JSF) vs Struts
I would have to say, the most common question or feedback came along the lines of comparing Struts to JSF. I thought it would be a good idea to compare JSF to Struts by evaluating various features that an application architect would look for in a Web application framework. This article will compare specific features.
In general, JSF is a much more flexible framework, but this is no accident. Struts is a sturdy framework and works well. JSF was actually able to learn a great deal from Struts projects. I see JSF becoming a dominant framework because of its flexible controller and navigation. Furthermore, JSF is built with integration and extensibility in mind. If you are starting a new project today, you'd have to consider many factors. If you have an aggressive schedule with not much time to deal with evaluating different vendors or dealing with support for new JSF implementations, Struts may be the way to go. But from a strategic direction and programming model, JSF should be the target of new applications. I encourage developers to take time to learn JSF and begin using them for new projects. In addition, I would consider choosing JSF vendors based on component set and RAD tools. JSF isn't easier than Struts when developing by hand, but using a RAD JSF tool like WebSphere Studio can greatly increase your productivity.
Solving the logout problem properly and elegantly
This article presents solutions for properly handling the logout problem along with sample programs. Author Kevin Le starts by describing an ideal password-protected Web application. He then uses sample programs to illustrate how the problems manifest themselves and discusses the solutions required to fix the problems. By centering the discussion on JavaServer Pages (JSP), the article presents the concepts that can be easily understood and adopted for other Web-tier technologies. Le concludes his discussion by showing how building Web applications with Jakarta Struts can more elegantly solve the logout problem. Sample programs for both JSP and Struts Web applications are included.
Unit Test Your Struts Application
This article introduces StrutsUT, a simple extension to the Cactus framework, to help solve this problem. It provides two solutions to unit test Struts applications: a "traditional" solution and one based on AspectJ. Developers can choose either for their convenience.
This article explains the initial idea of Cactus from a developer's point of view and extends this idea further into the Struts domain, which is the core of StrutsUT. The reader should have some knowledge of and experience in Struts framework, JUnit, Cactus, and/or AspectJ.
JUnit is a framework to create and perform unit tests on Java classes. With the help of mock objects and override technology, JUnit can perform unit tests for most Java applications. See References below to learn more about JUnit and mock objects. In this article, I chose EasyMock as the mock object implementation.
Struts best practices
The primary sources of information for this article are the Struts users' mailing list, the Struts developers' mailing list, and my experience with Struts-based applications.
The article discusses the following main points:
1. Screens with dynamic fields
2. Safeguarding JSP pages
3. Error categorization
4. Validation of service requester
5. Application security
7. Stack maintenance (for bread crumbs)
8. Context-related problems
9. Form-bean scope
10. Data transfer object implementation
12. Action chaining
Web app security using Struts, servlet filters, and custom taglibs
In this article, you have developed a powerful Web-based security architecture that is flexible enough to cater to a wide range of Web-based applications. You have also leveraged existing technologies such as Struts, which have helped maintain a clean separation of security and presentation code. You can also plug the security model into any existing application; it works well with third-party authentication providers.
Attribute-level security, although a useful feature in most applications, is often ignored because of the effort involved in its implementation and the degrading effect it has on application performance. The architecture defined in this article makes it easy to implement this useful feature without compromising on performance. The architecture also helps you maintain a clean separation between the security requirements and the functional requirements of the application. You, as the application developer, can concentrate on developing the business functionality without worrying about the security aspects, and your application is easier to maintain.
Rapid Struts Development
This article shows how Oracle JDeveloper 10g can help you automate a lot of Struts tasks and develop Struts applications. It details the development of a sample Struts application that demonstrates the usage of various Oracle JDeveloper 10g tools, such as the new Struts flow diagram.
One of the most useful features of Oracle JDeveloper 10g is the Struts flow diagram. Struts does a great job of managing flows in the application, but understanding these flows by looking through an XML configuration file can be quite difficult. With the Struts flow diagram, you can now easily depict, in just one diagram, all the flows in a system. The interactive nature of the diagram means that you can also make changes and additions to the application from within the diagram.
Reuse Tiles and Simplify UI
The Tiles framework was created to address this limitation and to enhance the Struts framework. Tiles extends the concept of reuse via includes by allowing you to define layouts (or templates) and then specify how the layouts are populated with content.
Now that you've seen the benefits of using the Tiles framework, here are the steps necessary for adding Tiles to your Struts application:
1. Add the Tiles Tag Library Descriptor (TLD) file to the application.
2. Create layout JSPs.
3. Update existing JSPs to use layouts.
4. Create a tiles-defs.xml file.
5. Update forward definitions in and add the Tiles plug-in to the struts-config.xml file.
6. Repackage and run the updated application.
A Practical Guide for Integrating EJB and Struts
You'll find plenty written about building and deploying EJB, and perhaps equally as much about building applications with the Struts framework. But what about leveraging EJB and Struts together? This tutorial lays out a complete step-by-step guide to integrating these two technologies, developing EJB components and incorporating them into Struts.
Posted on: February 13, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles