Java Reference
In-Depth Information
method value. This enables the Struts 2 framework to dynamically select the correct method to call
at runtime. Listing 4-43 illustrates booksByCategory() .
Listing 4-43. booksByCategory( )
public String booksByCategory() {
dao = new BookDAOImpl();
setBookList(dao.findBooksByCategory(category));
return "booksByCategory";
}
When booksByCategory() in the Listing 4-43 returns it is mapped to the tile name booklist as it was
illustrated in Line 5 of Listing 4-42. This maps to booklist defined in the tiles.xml as illustrated in
Listing 4-44 which renders the booklist.jsp file. Listing 4-44 illustrates the code fragment in
tiles.xml .
Listing 4-44. tiles.xml
1.<definition name="booklist" extends="baseLayout">
2.<put-attribute name="title" value="Log in"/>
3.<put-attribute name="menu" value="/menu.jsp"/>
4.<put-attribute name="body" value="/view/bookList.jsp"/>
5.</definition>
Listing 4-45 illustrates the bookList.jsp .
Listing 4-45. booklist.jsp
1.<%@ taglib uri="/struts-tags" prefix="s"%>
3.<body>
5.<div id="centered">
8.<s:form action=" selectedbooksLink" theme="simple">
9.<center>
10.<table id="grid">
11.<thead>
12.<tr>
13.<th id="th-title">Book Title</th>
14.<th id="th-author">Author</th>
15.<th id="th-price">Price</th>
16.</tr>
17.</thead>
20.<tbody>
22.<s:iterator value="bookList" id="book">
23.<tr>
25.<td>
26.<s:checkboxname="selectedBooks" fieldValue="%{bookId}" />
27. <s:propertyvalue="#book.bookTitle" />
29.</td>
Search WWH ::




Custom Search