Display Tag

display tag GUI thumbnail image

Open Source Version: http://www.displaytag.org/1.2/

The Display Tag is a Java JSP tag library that can be used to show data extracted from a List of objects in a simple and consistent way. It generates a simple two dimensional table by reflecting on the objects in the List provided to it. It provides functionality to page long lists, sort by column, export to various formats, and reporting features like drill down links, grouping, totaling, etc.

I was a speaker at the 2002 Java One Conference, presenting a BOF on the display tag. I made the source and documentation available and others helped enhance and support it. It became a popular tag library with Java developers. A neat moment was the first time that I was reviewing resumes for an open position, and finding a resume that listed the displaytag as a library they were familiar with. I think the usefulness of the library as it is currently designed is nearing an end, but I'm still waiting for the obvious AJAX based replacement.

Features and Functionality

Challenges and Lessons Learned

Keeping the design simple and appropriate. There is nothing revolutionary about this type of widget, every mature GUI programming environment has it's own version of a table tag. When designing this tag, I reviewed a number of similar widgets. At first I leaned towards implementing this with an API similar to the Swing table tag. I then decided Java developers are not typically both Swing and web developers, so making it similar to that widget would only help a small percentage of people and the web is not a rich GUI, so the model doesn't work well. Instead I made the API very similar to the existing struts tag libraries which most web developers where already familiar with.

Living within the taglib lifecycle. The display tag is a standard JSP taglib, which means it must follow the API and conventions dictated to it. This type of tag could easily be seen as an "iterator" type tag, which would allow me to expose the underlining business object (the current line being processed) up to the JSP page, so that a subtag could do additional processing. Pretty early on, I decided that approach wouldn't work for reasons documented in my examples. It was one of those design tradeoffs you sometimes have to make between keeping something pure and making it usable. Since it was a reasonable assumption that the user might expect the tag to work in this way, I included a specific page in the documentation to describe why I didn't implement it in that way, and show alternative solutions.

You can download all of the source code for the displaytag online if you want to look through it. I think the more important aspect of the display tag isn't the code itself (the open source folks were horrified at my lack of StringBuffer mastery), but rather my design approach. I tried to make it very easy to use the display tag, requiring very little setup, and providing a lot of functionality behind every extra XML attribute that the developer could choose to use or not.