Frequently Asked Questions
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.
- 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.
- 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.).
- Can I use a java variable as the value of the id attribute?
Displaytag and Struts
Exporting
Rendering
App Servers specific problems
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
andorg.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 useuid
instead ofuid
in the table tag.
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 haverequestURI="/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.
Exporting
- How can I disable an export options? I don't need export and I want to avoid any warning in the logs about missing itext classes or similar.
-
Just change che export.types configuration property as approriate (default is csv excel xml pdf removing any option you don't need)
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 thetbody
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
-
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
fromdisplaytag.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"
-
remove