Java Reference
In-Depth Information
The Contact List Action Bean
We'll name the action bean that retrieves the list of contacts ContactList-
ActionBean . The default event handler forwards to the JSP, and a get-
ter method returns the list of contacts by calling read ( ) on ContactDao
(implemented by MockContactDao ):
Download email_01/src/stripesbook/action/ContactListActionBean.java
package stripesbook.action;
public class ContactListActionBean extends BaseActionBean {
private static final String LIST="/WEB-INF/jsp/contact_list.jsp";
private ContactDao contactDao = MockContactDao.getInstance();
@DefaultHandler
public Resolution list() {
return new ForwardResolution(LIST);
}
public List<Contact> getContacts() {
return contactDao.read();
}
}
The Contact List JSP
ContactListActionBean forwards to contact_list.jsp , which renders an HTML
table by iterating over the list of contacts and creating a table row for
each contact:
Download email_01/web/WEB-INF/jsp/contact_list.jsp
<%@include file="/WEB-INF/jsp/common/taglibs.jsp"%>
Ê
<s:layout-render name="/WEB-INF/jsp/common/layout_main.jsp"
title="Contact List">
<s:layout-component name="body">
<table>
<tr>
<th> First name </th>
<th> Last name </th>
<th> Email </th>
</tr>
Ë
<c:forEach var="contact" items="${actionBean.contacts}">
<tr>
<td> ${contact.firstName} </td>
<td> ${contact.lastName} </td>
<td> ${contact.email} </td>
</tr>
</c:forEach>
</table>
</s:layout-component>
</s:layout-render>
 
 
 
Search WWH ::




Custom Search