|
Philip Chauvet
does Java, J2EE, Web and Application Development. |
|
<nav:alphanavbar:*> tag library |
<%-- AlphaNav: 1. Here we add the Alphabetical Navigation Bar Java Display Tag Library
library --%>
<%@ taglib uri="/tags/alphanavbar" prefix="nav" %>
<%
//Create a sample list
Object foo = session.getAttribute( "test" );
if( foo == null ) {
session.setAttribute( "test", new ReportList(10) );
}
%>
<%-- AlphaNav: 2. Here we add the Alphabetical Navigation Bar Java Display Tag Library --%>
<%-- Note: We are creating based on the 1st string column found. --%>
<%-- In this case it will be by Project. --%>
<nav:alphanavbar id="sublist" name="sessionScope.test" />
<%-- AlphaNav: 3. Get the new Alphabetical List and display it in the <display:*> tag --%>
<display:table name="requestScope.alphabeticalsublist" />
This is the simplest usage of the alphabetical navigation bar from the string data found in a java.util.List object. If there are no entries for a sublist, [A,B,C..Y,Z], the navigation bar does not allow the sublist to be selected. Also, since a "keycolumn" is not defined, the alphabetic list is created and sorted based on the the 1st string column found - in this case, the Project column.
The simplest possible usage of the table tag is to point the table tag at a java.util.List implementation and do nothing else. The table tag will iterate through the list and display a column for each property contained in the objects.
Typically, the only time that you would want to use the tag in this simple way would be during development as a sanity check. For production, you should always define at least a single column.
<%-- AlphaNav: 1. Here we add the Alphabetical Navigation Bar Java Display Tag Library
library --%>
<%@ taglib uri="/tags/alphanavbar" prefix="nav" %>
<%
//Create a sample list
Object foo = session.getAttribute( "test2" );
if( foo == null ) {
session.setAttribute( "test2", new TestList(15, false) );
}
%>
<%-- AlphaNav: 2. Here we add the Alphabetical Navigation Bar Java Display Tag Library --%>
<%-- Note: We are creating the list by Name . --%>
<nav:alphanavbar id="sublist" keycolumn="name" name="sessionScope.test2" />
<%-- AlphaNav: 3. Get the new Alphabetical List and display it in the <display:*> tag --%>
<display:table name="requestScope.alphabeticalsublist" />
<display:column property="id" title="ID" />
<display:column property="name" />
<display:column property="email" />
<display:column property="status" />
<display:column property="description" title="Comments"/>
</display:table>
In this example, the "Name" is the "keycolumn" used to create and sort the list when creating the alphabetical navigation bar from the string data found in a java.util.List object. The created alphebetical sublist, [A,B,C..Y,Z], are then passed to the familiar <display:*> tag which iterates through the sublist and display a column for each property contained in the objects.
This example starts to show you how to use the table tag. You point the table tag at a datasource (a List), then define a number of columns with properties that map to accessor methods (getXXX) for each object in the List.
Note that you have one column tag for every column that you want to appear in the table. And, the column specifies what property is shown in that particular row.
You can define the content of a column by adding a
property attribute to the column tag or adding a content to the
tag.
There are two ways to define the content of a column. Of
course, in the tag body you can use scriptlets or other custom tags. Using the
property attribute to define the content of a column is usually
faster and works better with sorting. If you add a property
attribute the tag body is ignored.
The property attribute specifies what getXXX method
is called on each item in the list. So for the second column,
getName is called. By default the property name is used as the
header of the column unless you explicitly give the column a title.