Table of Contents


preface xix
acknowledgments xx
about this book xxii


1  Basic recipes 1   
But what is Struts? 2
What Struts isn’t 3
A note about our favorite Ant 3
The developer’s environment 4
Chapter 1, in brief 5
1.1 Use Ant to automatically build a Struts project 6
1.2 Default your application to an ActionForward 14
1.3 What is “jsessionid” and why do I need it? 16
1.4 Using modules for large projects 19
1.5 Specifying a resource property file in a configuration 25
1.6 Multiple message-resources in an application 27
1.7 Using the bundle attribute in Struts’ custom tags 28
1.8 Manage constants throughout your application 32
1.9 Use <html:base/> for solid page references 35
1.10 Associating Cascading Style Sheets with Struts JSP pages 37
1.11 Implementing DynaActionForms 38
2  Forms and form elements 42   
2.1 Display errors and messages 44
2.2 Display errors next to a field 50
2.3 Create a custom message queue 53
2.4 Display errors and messages in groups 57
2.5 Dynamically insert data inside a message 62
2.6 Use message-resources property file from inside an Action 69
2.7 Create a wizard 73
2.8 Alternate row colors 80
2.9 Upload a file 89
3  Struts tag libraries 96   
Using Struts tag libraries to promote good MVC practice 97
What is a tag library? 99
What tags do we discuss in this chapter? 102
3.1 Using <html:link/> to increase your application’s maintainability 105
3.2 Rendering images mapped from a properties file using <html:img/> 109
3.3 Encoding information with a <bean:write/> tag 113
3.4 Using <bean:define/> to expose information to your pages 116
3.5 Use <bean:include/> for the simple server-side includes 122
3.6 Using <logic:present/> tags to determine page content 126
3.7 Debugging your GUI with the <logic:present/> tag 130
3.8 Using the <logic:equal/> tag for view decisions 134
3.9 Using <bean:resource/> to expose the struts.config.xml to your view 138
3.10 Using <html:rewrite/> to resolve URLs 147
3.11 Cleaning up session-scope attributes 153
3.12 Creating a basic Struts Tiles page 158
3.13 Using Tiles with XML Definitions 164
4  The Struts-Layout tag library 170   
Le Roi du Pot-au-feu 171
Pot-au-feu 171
What do layout tags do? 172
4.1 Configuring your application to use Struts-Layout tags 175
4.2 Creating a simple table with Struts-Layout tags 178
4.3 Creating a multicolumn dynamic table with Struts-Layout tags 182
4.4 Using Struts-Layout panels 187
4.5 Adding skins to your project with Struts-Layout 193
4.6 Creating a table with selectable rows using Struts-Layout 201
4.7 Creating a tree navigation scheme with Struts-Layout 206
4.8 Creating “bread crumb trails” with Struts-Layout 217
4.9 Creating tabbed panes with Struts-Layout 224
4.10 Implementing a “pager” with Struts-Layout 233
5  Validation within the Struts framework 242   
5.1 Use an ActionForm to validate 244
5.2 Struts Validator files explained (server-side) 247
5.3 Struts Validator files explained (client-side) 252
5.4 Use declarative exception handling 256
5.5 Aggregate exceptions 261
5.6 Tailor a form for a DispatchAction 268
5.7 Use Validator constants 276
5.8 Validation in a wizard 282
5.9 Create a pluggable validator for cross-form validation 287
6  Internationalization 294   
The “national language” of the United States 295
6.1 Set locale dynamically 296
6.2 Internationalize your text 298
6.3 Internationalize your images 302
6.4 Create a locale-sensitive ActionForward 305
6.5 Internationalize your tiles 309
6.6 Internationalize validation 312
7  Logging in, security, and guarding 317   
7.1 Tomcat domain authentication and Struts 320
7.2 Handling log out 326
7.3 Switch to SSL and back again 329
7.4 Secure an action mapping using the container 336
7.5 Customized action mapping security 338
7.6 Protect areas on a page 343
7.7 Protect fields 346
8  Advanced recipes 348   
Case study—a modern luxury hotel 349
Let’s revisit our B2C web application 351
8.1 Caching using a Struts plug-in 352
8.2 Use the Tiles controller 358
8.3 Generate a response with XSL 365
8.4 Generate a PDF 371
8.5 Hibernate and Struts 377
8.6 Layering applications 392
8.7 Enforce navigation 406
8.8 Use a database to store your message-resources properties 417
9  Testing 424   
9.1 Testing outside the container with StrutsTestCase 426
9.2 In-container testing with StrutsTestCase and Cactus 437
9.3 Testing DynaActionForm with StrutsTestCase 444
9.4 Testing modules 449
9.5 Performance testing Struts applications 454
9.6 Testing coverage 462
references 469
index 473