Welcome!

Java Authors: Ezhil Arasan Babaraj, Maureen O'Gara, Bruce Armstrong, Liz McMillan, Walter H. Pinson, III

Related Topics: Java

Java: Article

Development of Component-Oriented Web Interfaces

A Case for the Vitrage Framework

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 the contentlet is a Content Reference, these additional rules apply:
  • 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.
These requirements are quite modest, and the compartment occupies only a small part of a page. The table below contains key metrics summarizing implementations with BEA portal tag libraries and with Sun's JSTL, illustrating the complexity of implementing even the simple P&C Compartment using custom tags. The development was done by experienced Web programmers.

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.

  1. Direct support for key abstractions from the problem domain - compartments, contentlets and Presentation Logic.
  2. Produce clean, simple, easily maintainable JSPs free of any logical programming.
  3. 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.
  4. 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.
  5. Increase developer productivity.
  6. Ensure compatibility with a wide variety of existing J2EE platforms, MVC architecture and mainstream frameworks.
  7. Remain complementary to existing presentation technologies, and allow combining them when appropriate.
Vitrage Framework
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.

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

Comments (4) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
Alex Maclinovsky 04/07/05 01:15:09 PM EDT

I understand how immodest it is to leave feedback to my own article, however:
1) It took a verylong time for the article to get published, and a lot happened during this time. So both authours are no longer with RoundArch. I can be contacted at maclinovsky@yahoo.com
2) We did get the eprmission of RoundArch management to place Vitrage into public domain, but having switched jobs we never got to actually doing it. If you are interested in almost productized version, write to me. If enough people show interest we can start an open source project.
3) To answer Marina's question and preempt many other "... but have you seen ...?" ones. Yes it is a neat and very reach tag library, however it does nto change the fundamental issue that JSP is not a place to exercise imperative programming, in fact the richness of this library, would make the code required to implement a heavily compartmentalized page even harder to understand and maintain.

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
>tag libraries are designed to cover the basic HTML
>constructs like anchors, tables and forms.
maybe it is true for JSTL/JSF but have you seen Coldtags suite for example: http://www.servletsuite.com/jsp.htm ?