Frequently Asked Questions

General

  1. When I was trying to copy and paste the samples from the website I would get compile time errors looking for TestList, ReportList, etc. This would happen even if I included the display tag binary distribution jar file.
  2. One thing that I really wanted to do was create tables that contained things other than text fields. Drop Downs, CheckBoxes and Input Fields were stuff that I was looking for. On the examples page there wasn't an example that showed how to do this.
  3. What is the c tag library? In the examples there is a tag library called the c tag library which was used in a lot of places (c:if, c:out, etc.).
  4. Can I use a java variable as the value of the id attribute?

Displaytag and Struts

  1. How do I use this tag with Struts? The links that it creates for sorts and exports all point back to the JSP page, not my Action!

Rendering

  1. How can I display static headers in a table, so that headers remain visible while user scrolls the table body?

App Servers specific problems

  1. After deployed the displaytag war in JRun 4 I get a java.lang.NoClassDefFoundError: org/apache/log4j/Layout
  2. The <example> elements in the displaytag-el.tld and displaytag-12.tld are invalid according to JRun4. When adding displaytag.jar to a JRun4 web application I get the following stacktrace: jrun.jsp.compiler.JRunTagLibraryInfo$InvalidTLDElementException: The tag example on line 244 is not a valid TLD element at jrun.jsp.compiler.JRunTagLibraryInfo$TLDParser.startElement(JRunTagLibraryInfo.java:613)

General

General
When I was trying to copy and paste the samples from the website I would get compile time errors looking for TestList, ReportList, etc. This would happen even if I included the display tag binary distribution jar file.

Within the display tag binary distribution the "org.displaytag.sample" class files are not included. So if you are trying to use TestList, ReportList which are part of the org.displaytag.sample package you'll get a compile error telling you they can't find the classes. The solution I came up with was to download the source file distribution and copy the org.display.sample source files into your build. If you do this you probably need to copy over files from the org.displaytag.decorator and org.displaytag.exception packages since there are dependencies between them all.

One thing that I really wanted to do was create tables that contained things other than text fields. Drop Downs, CheckBoxes and Input Fields were stuff that I was looking for. On the examples page there wasn't an example that showed how to do this.

There is a really good example of how to use displaytag to create an editable row of data located at http://demo.raibledesigns.com/appfuse/demos/users-edit.jsp . It contains the source code for how to do it.

What is the c tag library? In the examples there is a tag library called the c tag library which was used in a lot of places (c:if, c:out, etc.).

The c tag library is actually the JavaServer Pages Standard Tag Library (JSTL). To import it you use the line <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> . You also have to download the library from sun and include the jstl.jar, standard.jar within your war, in the appropriate places.

Can I use a java variable as the value of the id attribute?

Yes, from version 1.0rc2 displaytag will allow you to use a java variable as the value of the id attribute. But you have to be aware that, while usually displaytag declares a variable named with the value of the id attribute, this is not possible when using a runtime expression. You can however fetch the value of the row object from the pagecontext, as showed in the following example.

                    
<% String myId = "row">
<display:table id="<%=myId%>" ...>
  <display:column><%=row%></display:column> <-- will not work
  <display:column><%pageContext.getAttribute("row")></display:column> <-- works 

                

In the EL version of the tag library you are also allowed to do:

                    
<c:set var="myId" value="row" />
<display:table id="${myId}" ...>
  <display:column><c:out value="${row}" /></display:column>

                

Note that pageContext.getAttribute() is the preferred way for accessing the object in the current row and the declared variable will probably be removed in future (it is already not used in the EL version of the tag library).

Some containers don't allow the id attribute to be a runtime expression at all (this has been reported in earlier versions of Tomcat 5 and ATG Dynamo 5), so an attribute with the name uid has been added. Simply use uid instead of uid in the table tag.

Displaytag and Struts

Displaytag and Struts
How do I use this tag with Struts? The links that it creates for sorts and exports all point back to the JSP page, not my Action!

Use the requestURI attribute of the column tag. When the requestURI attribute is present, links for sorting, exports, and paging are formed by adding any tag generated parameters to the value of requestURI attribute. So if your page is served under /ManageLatin.do , you should have requestURI="/ManageLatin.do" on your display:table.

Using the requestURI attribute with an empty "" attribute is another strategy. Sometimes you don't know what the uri is because the table might be part of an included tile. The resulting URL will be a link that is based upon the original requestURI + the appended display tag parameters.

Rendering

Rendering
How can I display static headers in a table, so that headers remain visible while user scrolls the table body?

You can do that simply using css, adding an height and the overflow: scroll property to the tbody element. Unfortunately this will work perfectly in Netscape/Mozilla, but not in Internet Explorer.

A table with a scrollable body can be made in Internet Explorer using javascript or a more complex css. Here you can find a good css example.

App Servers specific problems

App Servers specific problems
After deployed the displaytag war in JRun 4 I get a java.lang.NoClassDefFoundError: org/apache/log4j/Layout

This is due to a known bug in JRun.

To make the sample webapp working you will need to:

  • remove commons-logging-*.jar from displaytag.war/WEB-INF/lib
  • move log4j-1.2.8 to $JRUN/servers/lib/ (create this directory if it doesn't exist)

You can find more info related to this jrun bug on google: searching jrun "org/apache/log4j/Layout"

The <example> elements in the displaytag-el.tld and displaytag-12.tld are invalid according to JRun4. When adding displaytag.jar to a JRun4 web application I get the following stacktrace: jrun.jsp.compiler.JRunTagLibraryInfo$InvalidTLDElementException: The tag example on line 244 is not a valid TLD element at jrun.jsp.compiler.JRunTagLibraryInfo$TLDParser.startElement(JRunTagLibraryInfo.java:613)

Again, this appears to be a JRun fault.

The <example> elements are absolutely valid according to the sun dtd http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd but JRun doesn't accept them. A bug report has already been submitted to Macromedia hoping they will fix this.

In the meanwhile, you have two available solutions to make displaytag work pacefully with JRun:

  • If you don't need to use the EL version, simply delete the displaytag-el.tld and displaytag-12.tld files from displaytag.jar and use the 1.1 version. This one works without problems.
  • If you need the EL version, extract displaytag-el.tld from the jar and remove all the <example> tags. Replace the original tld in the jar with this modified one.

We are sorry for this extra step needed with JRun, but at the moment we decided to not to remove the example tags in the main tld since they are needed for the generated documentation.