Web application components made easy with Composite View
Implement Web applications featuring pluggable components with the Composite View design pattern
By David Geary, JavaWorld.com, 12/28/01
- Digg
- Reddit
- SlashDot
- Stumble
- del.icio.us
- Technorati
- dzone
In
Core J2EE Patterns: Best Practices and Design Strategies, Deepak Alur, John Crupi, and Dan Malks identify 15 J2EE (Java 2 Platform, Enterprise Edition) design patterns, of which the
Composite View pattern proves to be one of the most compelling. The Composite View pattern builds composite views from multiple
subviews, with the potential to greatly simplify application development by allowing content and layout to be plugged into
a framework.
Before the Composite View pattern was widely known, developers knew it as JSP (Java Server Pages) templates; a term that originated
in Sun's J2EE Blueprints. Templates combine the Composite and Strategy patterns (both espoused by the Gang of Four (GOF) in Design Patterns) to separate both content and layout from JSPs. Such separation defines a JSP programming style that lets page authors and
software developers work, for the most part, independently.
The templates description in J2EE Blueprints motivated me to write a templates custom tag library, which I contributed to the Apache Struts project in fall 2000. Not long after that, I wrote about that tag library for JavaWorld in "JSP Templates" (September 2000). Consequently, feedback from both JavaWorld readers and Struts users prompted me to rewrite the templates tag library from scratch for my book Advanced JavaServer Pages.
In spring 2001, I contributed some code from the rewritten templates tag library -- now known as the regions tag library -- to illustrate the Composite View J2EE design pattern in the aforementioned Core J2EE Patterns: Best Practices and Design Strategies.
This article discusses the Composite View pattern by exploring the regions tag library in more detail. Also, because the tag
library examined in this article is a second revision of the library discussed in JavaWorld's "JSP Templates," you can view this article as somewhat of a sequel.
The Composite View pattern
Nearly all modern object-oriented development environments support three key objects for flexible and extensible graphical
user interface (GUI) development: components, containers, and layout managers. Components represent graphic objects such as text, buttons, or lists. Containers maintain component lists, while layout managers
position and size (or lay out) a container's components.
Developers typically implement components and containers with the GOF Composite design pattern, which lets you compose graphical
objects into tree hierarchies. Meanwhile, layout managers are typically implemented with the GOF Strategy design pattern,
so that you can change a container's layout strategy at runtime without changing the container itself. For its part, the J2EE
Composite View design pattern acts as a recipe for components, containers, and layout managers for JSP-based Web applications.
At the low end, the Composite View pattern resembles the GOF Composite pattern. In describing the Composite View pattern in
Core J2EE Design Patterns, Alur, Crupi, and Malks write, "Use composite views that are composed of multiple atomic subviews...," which means your views
should be composites that can contain other views -- an endorsement of the GOF Composite pattern. Those views can be composites
also, so you can arrange views in a tree hierarchy.
- Digg
- Reddit
- SlashDot
- Stumble
- del.icio.us
- Technorati
- dzone
Resources
- To download this article's complete source code as a jar file, go to
http://www.javaworld.com/javaworld/jw-12-2001/jsptemplate/jw-1228-jsptemplate.jar
- David Geary's "JSP Templates," (JavaWorld, September 2000) shows how to use JSP templates to encapsulate Webpage layout and encourage modular design
http://www.javaworld.com/javaworld/jw-09-2000/jw-0915-jspweb.html
- David Geary's Advanced JavaServer Pages (Prentice Hall, 2001; ISBN0130307041) features the regions tag library
http://www.amazon.com/exec/obidos/ASIN/0130307041/javaworld
- David Geary also writes JavaWorld's monthly Java Design Patterns column
http://www.javaworld.com/columns/jw-java-design-patterns-index.shtml
- Core J2EE PatternsBest Practices and Design Strategies, Deepak Alur, John Crupi, Dan Malks (Prentice Hall, 2001; ISBN0130648841)
http://www.amazon.com/exec/obidos/ASIN/0130648841/javaworld
- "J2EE Design Patterns" (Sun Microsystems, 2001) from the J2EE Blueprints series offers good information on design patterns for J2EE projects
http://java.sun.com/blueprints/patterns/j2ee_patterns/index.html
- The Apache Struts project
http://jakarta.apache.org/struts/index.html
- The famous Gang of Four bookDesign Patterns, Eric Gamma, Richard Helm, Ralph Johnson, and John Vlissides (Addison-Wesley Publishing Co., 1995; ISBN0201633612)
http://www.amazon.com/exec/obidos/ASIN/0201633612/javaworld
- Design Object-Oriented Software, Rebecca Wirfs-Brock, Brain Wilkerson, and Lauren Wiener (Prentice Hall, 1990; ISBN0136298257)
http://www.amazon.com/exec/obidos/ASIN/0136298257/javaworld
- Learn how to employ popular design patterns to overcome unit-testing hurdles with "Pattern Your Way to Automated Regression
Testing," Kevin Pauli (JavaWorld, September 2001)
http://www.javaworld.com/javaworld/jw-09-2001/jw-0921-test.html?
- For more design pattern stories, visit the Design Patterns section of JavaWorld's Topical Index
http://www.javaworld.com/channel_content/jw-patterns-index.shtml
- To read more about JavaServer Pages, browse our Topical Index
http://www.javaworld.com/channel_content/jw-jsp-index.shtml
- Speak out in our Java Forum
http://forums.idg.net/webx?13@@.ee6b802
- Sign up for JavaWorld's free weekly email newsletters
http://www.javaworld.com/jw-subscribe
- You'll find a wealth of IT-related articles from our sister publications at IDG.net
what a black maizeBy Anonymous on October 15, 2009, 7:14 amwhat a black maize
Reply | Read entire comment
View all comments