Java Reference
In-Depth Information
30.<td>
31.<s:iterator value="#book.authors" id="author">
32.<s:if test="%{#book.id == #author.bookId}">
33.<s:property value="#author.firstName" />
34.<s:property value="#author.lastName" />
35.</s:if>
36.</s:iterator>
37.</td>
39.<td><s:property value="price" /></td>
40.</tr>
42.</s:iterator>
43.</tbody>
45</table>
47.</center><br>
49.<s:submit value="Add to the shopping cart" />
51.</s:form>
52.
53.</div>
54.</body>
Listing 4-45 illustrates the usage of Struts 2 tags and how Struts 2 OGNL is used to navigate the
property bookTitle on line 27 and the properties firstName and lastName (of the author) on
lines 33 and 34. Line 31 illustrates the usage of a simple and nested s:iterator . Line 26 allows the
user to select books to add to the shopping cart. The user can check the books to select and submit
them by clicking the button on line 49. When the user clicks the Add to Cart button, the action
name selectedbooksLink on line 8 and the book Id on line 26 are sent to the container, which is then
mapped to the AddToCart action via struts.xml . The AddToCart action then stores the book to the cart
in the database, and the AddToCart action returns the String success , which is mapped via action
mapping in struts.xml and the tile in the tiles.xml file to the view selectedBooks.jsp . The user
can click the Purchase button on the selectedBooks.jsp page to call PurchaseAction in the same
manner. This chapter sketched a brief overview of Struts 2. For more detailed coverage of Struts 2,
I recommend Practical Apache Struts 2 Web 2.0 Projects by Ian Roughley.
Summary
In this chapter, you saw the Struts 2 framework's core components, which follow the MVC design
pattern, and you saw how Struts 2separates the cross-cutting concerns by means of interceptors. You
saw how the Struts 2 framework provides a declarative architecture in two forms: XML and annotations.
In the next chapter, you will learn another action-oriented framework, called Spring Web MVC.
 
Search WWH ::




Custom Search