| By Alexey Yakubovich, Alex Maclinovsky | Article Rating: |
|
| March 9, 2005 12:00 AM EST | Reads: |
30,191 |
Custom Tags as the Prevalent Choice
Custom tag technology has become the most prevalent tool in developing dynamic JSP user interfaces. It gained acceptance because it promised to separate the presentation from the content, eliminate Java programming from JSPs and let HTML designers use familiar tag syntax.
Tag libraries work really well in many cases, but become less usable in more complicated cases, particularly when JSPs need to implement the non-trivial presentation logic often required by compartments. That's why publications promoting tag libraries never go beyond the simplest examples3. Sun's implementation of Pet Store illustrates this point perfectly. Pet Store serves as a blueprint for building applications using J2EE technologies like JSTL tags, but the most complex table is limited to static columns and doesn't have any presentation logic.
A Real-Life Example
To see how this works in the real world, consider the P&C Compartment presented in 0 that came from an actual application.
The compartment is designed to present a collection of contentlets arranged in a one-column table, one object per cell. Contentlets are considered renderable as long as they have one core attribute defined. The following requirements should also be satisfied:
- Invalid and unrenderable contentlets should be omitted
- If no contentlets were rendered, the entire table with its header, footer, frame and background should not be rendered
- Visual attributes should be arranged vertically in the following order: image, followed by name, then description - if an attribute is undefined, it should be omitted.
- If an image is present, it should be rendered as the link
- If there is no image, the name should be rendered as the link
- The description is never rendered as a link.
The actual JSP code is too complex to be presented here although it's available online, along with a more in-depth analysis in the form of a whitepaper. This implementation would not be significantly simplified by using portlets or Tiles templates.
Using this approach to develop a page with 10 or more compartments will result in thousands of lines of JSP code, making it highly inefficient for implementing applications similar to the ones presented in Figure 1.
Why Tags Fail
The reason custom tags lead to such complexity is that tag libraries are designed to cover the basic HTML constructs like anchors, tables and forms.
They are effective when the layout doesn't depend on content. The later tag library extensions supporting loops, conditions and other control flow constructs inside a JSP (i.e., iteration, choice and choiceMethod) have very limited capabilities and poor expressive power for programming presentation logic.
In other words, tag libraries force developers to program in a primitive language that lacks clear structure and doesn't allow code reuse beyond simple includes and cut-and-paste. To complicate things, there are many incompatible flavors of this language, each with its own quirks and limitations. For example, BEA's netui-data library let one use choice statements only inside a loop, while a c:url tag in a JSTL doesn't support named anchors.
It has been firmly established that a JSP is not a good place for exercising imperative programming, be it java scriplets programming or tag programming. A new approach is needed that can solve the problem of developing dynamic compartmentalized applications effectively.
Success Criteria
How would you measure the success of this new approach? Previous analysis has helped formulate key criteria for its success.
- Direct support for key abstractions from the problem domain - compartments, contentlets and Presentation Logic.
- Produce clean, simple, easily maintainable JSPs free of any logical programming.
- Use appropriate means to express different presentational aspects - let programmers implement logic and data manipulation in Java, while allowing Web designers to define visual design using familiar syntax and tools.
- Facilitate both physical and logical reuse, allowing presentation components to be used in multiple places and combined into more complex ones, as well as reuse of common functionality through inheritance and delegation.
- Increase developer productivity.
- Ensure compatibility with a wide variety of existing J2EE platforms, MVC architecture and mainstream frameworks.
- Remain complementary to existing presentation technologies, and allow combining them when appropriate.
In developing large information portals, we have faced all the challenges described in the first half of this article. Having experienced the disappointments of existing approaches, we set out to develop a new solution that would meet the criteria outlined above. The result is called the Vitrage Framework, vitrage being the French word for stained glass. Vitrage is a solution centered around the notion of JSP-blocks. A JSP-block is the Java realization of compartment abstraction.
Architecture
The diagram in Figure 4 presents the structural components of the Vitrage Framework. It contains three major components: HTML Code Generation, Vitrage Container and Development Tools. The HTML generation itself is implemented on three levels: formatters, renders and blocks. Each layer uses components of lower layers and adds some new functionality.
Formatters
Formatters are used to generate elementary HTML tags with parameters at runtime. Tag parameters can specify layout attributes (such as background, border and span), as well as functional attributes (such as name, value and href). Formatters provide the low-level HTML-specific structure for JSP-blocks.
Renders
Renders use formatters as building blocks. There are three layers of renders: content renders, HTML element renders and Composite renders. All renders implement an interface ARender. This interface has two key methods:
String build(Object o, ICondition c);
void setLayout(ILayout l);
The method build() is invoked to generate HTML fragment, the method setLayout() is used to specify layout parameters for a render.
Content renders are responsible for presenting actual content. Currently, this category includes several flavors of contentlet renders. Vitrage implements a number of content renders with internal managers or Oracles that cover a variety of presentation strategies for contentlets. Another useful type of content render is Document Render, which can be used to embed an entire file into a page. Additional domain-specific renders can be implemented if required.
Published March 9, 2005 Reads 30,191
Copyright © 2005 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Alexey Yakubovich
Alexey Yakubovich works as a framework architect at Roundarch, Inc. He received his PhD in mathematics in Moscow State University for research in mathematical logic, and has published more than two dozen articles in mathematical magazines. Alexey has spent 20 years in software development.
More Stories By Alex Maclinovsky
Alex works at Sun Microsystems as the Engineering Manager for Sun SOA Governance Solution. For nearly two decades he architected and built distributed systems on enterprise, national and global scale. Alex specializes in SOA Infrastructure, Security and Composite Applications. He blogs at http://blogs.sun.com/RealSOA/ and can be contacted at maclinovsky@yahoo.com
![]() |
Alex Maclinovsky 04/07/05 01:15:09 PM EDT | |||
I understand how immodest it is to leave feedback to my own article, however: |
||||
![]() |
Jack C. Holt 03/30/05 11:49:23 AM EST | |||
I just tried to send email to the email addresses for the authors and my email server is telling me that those email addresses don't exist. How can I reach the authors? |
||||
![]() |
Jack C. Holt 03/30/05 11:34:31 AM EST | |||
Unfortunately, I noticed some typos in this article. For instance the white paper for Vitrage is actually at http://www.roundarch.com/features/vitrage.html. I would have appreciated a link to where I can download the code Vitrage code. |
||||
![]() |
Marina Prikaschikova 03/22/05 09:54:46 AM EST | |||
>The reason custom tags lead to such complexity is that |
||||
- Kindle 2 vs Nook
- Why IBM’s Server Chief Got Busted
- Is Cloud Computing Like Teenage Sex?
- Industry Experts Discuss the State of Cloud Computing
- Performance Tuning Essentials for Java
- Confessions of a Ulitzer Addict
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- It's the Java vs. C++ Shootout Revisited!
- Cloud Computing Can Revitalize Your Career as Software Developer
- IBM Could "Reinvent" Java: Mills
- Oracle & Cloud Computing: Exclusive Q&A with SVP Richard Sarwal
- A Brief History of Cloud Computing
- Kindle 2 vs Nook
- Cloud CEOs, CTOs & SVPs to Speak at 4th International Cloud Computing Expo
- Why IBM’s Server Chief Got Busted
- Is Cloud Computing Like Teenage Sex?
- Industry Experts Discuss the State of Cloud Computing
- Performance Tuning Essentials for Java
- The Difference Between Web Hosting and Cloud Computing
- Cloud Computing Expo: Exclusive Q&A with Yahoo! SVP Cloud Computing
- Ajax in RichFaces 3.3, JSF 2 and RichFaces 4
- Confessions of a Ulitzer Addict
- My Thoughts on Ulitzer
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- A Cup of AJAX? Nay, Just Regular Java Please
- Java Developer's Journal Exclusive: 2006 "JDJ Editors' Choice" Awards
- The i-Technology Right Stuff
- JavaServer Faces (JSF) vs Struts
- Rich Internet Applications with Adobe Flex 2 and Java
- Java vs C++ "Shootout" Revisited
- Bean-Managed Persistence Using a Proxy List
- Reporting Made Easy with JasperReports and Hibernate
- Creating a Pet Store Application with JavaServer Faces, Spring, and Hibernate
- What's New in Eclipse?
- Why Do 'Cool Kids' Choose Ruby or PHP to Build Websites Instead of Java?
- i-Technology Predictions for 2007: Where's It All Headed?







































