Struts in Action
From the publisher:
Struts solves the most common problems of web development. By basing your application on the Struts web application framework, you can reuse proven solutions and focus on what's unique to your own case. Struts is an open-source product distributed by the Apache Software Foundation.
Struts in Action is a comprehensive introduction to the Struts framework. It covers initial design, data validation, database access, dynamic page assembly, localization, product configuration, and other important areas. It shows you how to use both JSP tags and Velocity templates. It carefully explains the Struts architecture and control flow, as well as how to extend framework classes.
Differences between Struts 1.1 and Struts 1.0. are pointed out and a case-study illustrates the 1.0 to 1.1 transition. The book shows you dozens of proven design techniques, patterns, and strategies, many of them not found elsewhere. By providing you with practical examples of realistic uses of Struts this book helps you learn through action.
What's Inside:
- Struts 1.1 and 1.0
- Jakarta Validator and Tile packages
- Jakarta Scaffold toolkit
- Velocity templates
- HTTP, Java Servlets, and JSP tags
- Dynamic web programming
- Servlet centric application designs
- Working with databases and data services
- Design and development patterns
- Tons of examples
The lead author, Ted Husted, is a consultant and an acknowledged Struts authority. He is a manager of the jGuru Struts forum and a core member of the Struts development team.
Developing applications
with Tiles
Co-authored by Cedric Dumoulin and Ted Husted
This chapter covers
-
Designing applications with dynamic includes
-
Using the Struts and Tiles frameworks together
-
Understanding Tiles Definitions and attributes
-
Migrating applications to Tiles
|
A foolish consistency is the hobgoblin of little minds, adored by little
statesmen and philosophers and divines.
Leveraging layouts
Usability is a prime concern in the design of today's applications--and consistency is a prime ingredient of usability. Users want to stay focused on the task at hand and are easily annoyed by any small inconsistency in an application's interface or screen layout.
-
Consistency is no small challenge for a dynamic web application; it is commonplace for each page to be coded by hand. Layout tools for static pages are available to most designers today, but few of these are available to applications based on JavaServer Pages.
-
Worse, the look and feel of an application is usually the last detail to be finalized, and then it will often change between versions--or even arbitrarily as part of a greater website "relaunch." This can create a nightmarish round of last-minute coding and testing--even if only to alter the background color or add a new link to the menu bar.
-
Of course, consistency is more than a hobgoblin; it's a hallmark of good design. Like any other component, web pages contain many common elements, headers, footers, menus, and so forth. Often, these are cut-and-pasted from one page to the next. But like any component, bugs are found and features are enhanced, leading to another round of cut-and-paste "reuse."
-
In a web application, page markup is a programming component like any other and should be held to the same standard of reuse.
Layering with dynamic templates
In the first part of this book, we stressed the importance of layering an application to isolate the effects of change. By compartmentalizing an application, we can change one piece without disrupting the other pieces. The same concept can be applied within the presentation layer to separate the look and feel from the actual content.
-
One approach to separating layout from content is the use of dynamic JSP includes. The JSP specification provides for both static and dynamic includes. The standard JSP action for a dynamic include is
<jsp:include>
.
-
We make use of dynamic includes by breaking the server page into several fragments, each with its own job to do. A background template can set the default format and layout, and page fragments can be included at runtime to provide the content. A dynamic include folds the output of the included page into the original page. It acts like a switch that moves processing over to a page fragment and then back to the caller. As shown in See The effect of the <jsp:include> action on the processing of a request, the included template is processed normally, just as if it had been called on its own.
The Tiles framework, which we explore in this chapter, uses a more advanced form of the JSP include action. In a Tiles application, the background, or layout, template usually defines the position of a header, menu body, content, and footer. Other pages are then included to fill each of these positions. If the header changes, then only that template file need be changed. The change is automatically reflected in all pages that include that template. The effects of changes are minimized--and the hobgoblins appeased.
-
Standard HTML components, like Cascading Style Sheets (CSSs), also work well with dynamic templates. A style sheet can help keep the templates internally consistent and further minimizes the effects of change.
Template consequences
Every technology comes bundled with compromises. Here are some consequences--pro, con, and mixed--that come with using dynamic templates in your application:
-
The JSP include technology is well established and reliable, and tends to scale well in larger applications. The underlying technology for including dynamic templates is part of the core Java Servlet API.
-
Most containers are optimized for JSPs and standard features like servlet include.
-
The included pages typically output HTML fragments and are not synoptically complete. This can prevent you from maintaining templates with standard HTML editors, which expect markup to be part of a complete, stand-alone page.
-
Most sites recompile JSP pages when the source changes. Templates create more pages to be monitored for such changes.
-
Templates actually reuse code that would otherwise be duplicated from page to page. This can result in a significantly smaller footprint and conserve server resources.
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.