A Framework for Enterprise Java
Total Page:16
File Type:pdf, Size:1020Kb
Seam - Contextual Components A Framework for Enterprise Java 2.1.2 by Gavin King, Pete Muir, Norman Richards, Shane Bryzak, Michael Yuan, Mike Youngstrom, Christian Bauer, Jay Balunas, Dan Allen, Max Rydahl Andersen, Emmanuel Bernard, Nicklas Karlsson, Daniel Roth, Matt Drees, Jacob Orshalick, and Marek Novotny edited by Samson Kittoli and thanks to James Cobb (Graphic Design), Cheyenne Weaver (Graphic Design), Mark Newton, Steve Ebersole, Michael Courcy (French Translation), Nicola Benaglia (Italian Translation), Stefano Travelli (Italian Translation), Francesco Milesi (Italian Translation), and Japan JBoss User Group (Japanese Translation) Introduction to JBoss Seam ............................................................................................ xvii 1. Contribute to Seam ............................................................................................. xxi 1. Seam Tutorial .............................................................................................................. 1 1.1. Using the Seam examples .................................................................................. 1 1.1.1. Running the examples on JBoss AS ......................................................... 1 1.1.2. Running the examples on Tomcat ............................................................. 1 1.1.3. Running the example tests ....................................................................... 2 1.2. Your first Seam application: the registration example ............................................ 2 1.2.1. Understanding the code ........................................................................... 3 1.2.2. How it works .......................................................................................... 14 1.3. Clickable lists in Seam: the messages example .................................................. 15 1.3.1. Understanding the code .......................................................................... 15 1.3.2. How it works .......................................................................................... 21 1.4. Seam and jBPM: the todo list example ............................................................... 21 1.4.1. Understanding the code .......................................................................... 22 1.4.2. How it works .......................................................................................... 29 1.5. Seam pageflow: the numberguess example ........................................................ 30 1.5.1. Understanding the code .......................................................................... 31 1.5.2. How it works .......................................................................................... 39 1.6. A complete Seam application: the Hotel Booking example ................................... 40 1.6.1. Introduction ............................................................................................ 40 1.6.2. Overview of the booking example ............................................................ 42 1.6.3. Understanding Seam conversations ......................................................... 42 1.6.4. The Seam Debug Page .......................................................................... 51 1.7. Nested conversations: extending the Hotel Booking example ............................... 52 1.7.1. Introduction ............................................................................................ 52 1.7.2. Understanding Nested Conversations ...................................................... 54 1.8. A complete application featuring Seam and jBPM: the DVD Store example ........... 60 1.9. Bookmarkable URLs with the Blog example ........................................................ 62 1.9.1. Using "pull"-style MVC ............................................................................ 63 1.9.2. Bookmarkable search results page .......................................................... 65 1.9.3. Using "push"-style MVC in a RESTful application ..................................... 68 2. Getting started with Seam, using seam-gen .............................................................. 73 2.1. Before you start ................................................................................................ 73 2.2. Setting up a new project ................................................................................... 74 2.3. Creating a new action ....................................................................................... 77 2.4. Creating a form with an action ........................................................................... 78 2.5. Generating an application from an existing database ........................................... 79 2.6. Generating an application from existing JPA/EJB3 entities ................................... 80 2.7. Deploying the application as an EAR ................................................................. 80 2.8. Seam and incremental hot deployment ............................................................... 80 2.9. Using Seam with JBoss 4.0 ............................................................................... 81 2.9.1. Install JBoss 4.0 .................................................................................... 81 2.9.2. Install the JSF 1.2 RI ............................................................................. 82 iii Seam - Contextual Components 3. Getting started with Seam, using JBoss Tools .......................................................... 83 3.1. Before you start ................................................................................................ 83 3.2. Setting up a new Seam project .......................................................................... 83 3.3. Creating a new action ....................................................................................... 99 3.4. Creating a form with an action ......................................................................... 101 3.5. Generating an application from an existing database ......................................... 102 3.6. Seam and incremental hot deployment with JBoss Tools ................................... 104 4. The contextual component model ........................................................................... 105 4.1. Seam contexts ................................................................................................ 105 4.1.1. Stateless context .................................................................................. 105 4.1.2. Event context ....................................................................................... 106 4.1.3. Page context ........................................................................................ 106 4.1.4. Conversation context ............................................................................ 106 4.1.5. Session context .................................................................................... 107 4.1.6. Business process context ..................................................................... 107 4.1.7. Application context ............................................................................... 107 4.1.8. Context variables .................................................................................. 107 4.1.9. Context search priority .......................................................................... 108 4.1.10. Concurrency model ............................................................................. 108 4.2. Seam components .......................................................................................... 109 4.2.1. Stateless session beans ....................................................................... 109 4.2.2. Stateful session beans .......................................................................... 110 4.2.3. Entity beans ......................................................................................... 110 4.2.4. JavaBeans ........................................................................................... 111 4.2.5. Message-driven beans .......................................................................... 111 4.2.6. Interception .......................................................................................... 111 4.2.7. Component names ............................................................................... 112 4.2.8. Defining the component scope .............................................................. 114 4.2.9. Components with multiple roles ............................................................. 114 4.2.10. Built-in components ............................................................................ 115 4.3. Bijection .......................................................................................................... 115 4.4. Lifecycle methods ........................................................................................... 118 4.5. Conditional installation ..................................................................................... 119 4.6. Logging .......................................................................................................... 120 4.7. The Mutable interface and @ReadOnly ............................................................. 121 4.8. Factory and manager components ................................................................... 124 5. Configuring Seam components ..............................................................................