200 CHAPTER 4: Building a Web Application Using Struts 2
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.
2.
3.
4.
5.
Listing 4-45 illustrates the bookList.jsp.
Listing 4-45. booklist.jsp
1.<%@ taglib uri="/struts-tags" prefix="s"%>
3.
5.
8.
9.
10.
Book Title | Author | Price |
---|---|---|
26.
|