Java Reference
In-Depth Information
At Ê we're using the layout that we created earlier, with “Contact List”
as the page's title. The page's body is the content between the <s:layout-
component> tags.
After some standard table-rendering HTML, at Ë we retrieve the list
of contacts from the action bean with ${actionBean.contacts} and loop
using the JSTL's <c:forEach> tag. Each individual contact is placed in
the contact variable. We can then create rows of data and display the
contact information by accessing the properties of contact .
Putting It All Together
Combining everything that we've created so far, we can obtain the con-
tact list with the /ContactList.action URL. This triggers the default event
handler of ContactListActionBean , which forwards to contact_list.jsp . In
this JSP, the action bean is available via ${actionBean} , so ${action-
Bean.contacts} calls getContacts ( ) and obtains the list of contacts, which
is then displayed in a table. This sequence is illustrated in Figure 3.2 ,
on the next page, and the resulting table is shown in Figure 3.3 , on
page 50 .
As you can see, the MockContactDao comes with batteries included—it
is prepopulated with a list of ten contacts. 3
So far so good. But you've probably noticed that the table looks rather
bland. Let's pretty it up.
Using Display Tag
Display Tag ( http://displaytag.sourceforge.net/ ) is a library for creating
HTML tables. It is not part of Stripes, and it isn't required in order
to use Stripes. But we'll use it as an example of how easy it is to inte-
grate a third-party library that does what we want instead of having
to write the code ourselves. Display Tag automatically makes the data
sortable by clicking the column headers and adds CSS classes so that
we can shade odd and even rows in different colors. The code in the
JSP becomes even simpler—we get more for less.
To use Display Tag, add its required JAR files to the /WEB-INF/lib direc-
tory, and declare the library in taglibs.jsp :
Download email_02/web/WEB-INF/jsp/common/taglibs.jsp
<%@taglib prefix="d" uri="http://displaytag.sf.net"%>
3. The names are fictitious. They were obtained using the Random Name Generator
( http://www.xtra-rant.com/gennames ) .
 
 
Search WWH ::




Custom Search