Jboss Seam Tion That Frameworks Such As Struts Provided and Brings It to the Next Level
Total Page:16
File Type:pdf, Size:1020Kb
CYAN YELLOW MAGENTA BLACK PANTONE 123 CV EMPOWERING PRODUCTIVITY FOR THE JAVA™ DEVELOPER THE EXPERT’S VOICE® IN JAVA™ TECHNOLOGY Companion eBook Available Beginning JBoss® Seam: From Novice to Professional Dear Reader, Beginning Since the late ’90s when Java™ enterprise development started to move into full JBoss swing, there has been a steady upsurge of Java specifications (for example, JSF™ and EJB™3) and Java-based frameworks (for example, Apache Struts and Interface21 Spring). All of these were created with the idea of making life easier for the developer. However, they were always missing the glue to hold them together seamlessly. This is where JBoss® Seam comes into the picture. Seam is a framework designed to eliminate the headache of creating middle- Beginning man objects that enable your JSF pages to talk directly to your EJB3 beans. With Seam, your JSF pages are able to call EJB3 beans without you having to create middleman beans. Seam accomplishes this in a nonintrusive manner, which still allows the running of your JSF and EJB3 components’ full life cycle. ® I found all this abstraction very exciting when I first read about Seam because I seemed to be spending far too much time writing repetitive code for ® many projects. Frameworks such as Struts were awesome at first, removing the Seam need to write and code servlets. However, at times even these seemed to require too much repetitive behavior with the Action classes. Seam offers the abstrac- JBoss Seam tion that frameworks such as Struts provided and brings it to the next level. I have written this book for anyone from a beginner to an expert in Java development to be able to take away a solid understanding of Seam. The first chapters are devoted to understanding the fundamental concepts of Java 5 and basic web design, as well as JSF and EJB3. From there, we delve into exploring From Novice to Professional Seam fully, including a chapter on using it with jBPM. By the end of this book, you will be able to develop and run full-fledged Java EE applications by using Seam as the connector, which will hopefully save you time. And in today’s world, time is money. Companion eBook Joseph Faisal Nusairat Learn to build enterprise and next generation Web 2.0 applications using this powerful, open source lightweight Java™ EE 5 application framework. THE APRESS JAVA™ ROADMAP See last page for details Beginning Hibernate on $10 eBook version Practical JBoss® Seam Beginning POJOs Beginning JBoss® Seam Join online discussions: Web 2.0 Projects java.apress.com Pro Ajax and Java™ Frameworks Nusairat SOURCE CODE ONLINE ISBN-13: 978-1-59059-792-7 Joseph Faisal Nusairat www.apress.com ISBN-10: 1-59059-792-3 53999 US $39.99 Shelve in Java Programming User level: 9 781590 597927 Beginner–Intermediate this print for content only—size & color not accurate spine = 0.875" 376 page count 7923FMCMP2 2/2/07 10:47 AM Page i Beginning JBoss® Seam From Novice to Professional Joseph Faisal Nusairat 7923FMCMP2 2/2/07 10:47 AM Page ii Beginning JBoss® Seam: From Novice to Professional Copyright © 2007 by Joseph Faisal Nusairat All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN-13 (pbk): 978-1-59059-792-7 ISBN-10 (pbk): 1-59059-792-3 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. Java™ and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc., in the U.S. and other countries. Apress, Inc., is not affiliated with Sun Microsystems, Inc., and this book was written without endorsement from Sun Microsystems, Inc. JBoss® is a registered trademark of Red Hat, Inc., in the U.S. and other countries. Apress, Inc., is not affili- ated with Red Hat, Inc., and this book was written without endorsement from Red Hat, Inc. Lead Editor: Steve Anglin Technical Reviewer: Floyd Carver Editorial Board: Steve Anglin, Ewan Buckingham, Gary Cornell, Jason Gilmore, Jonathan Gennick, Jonathan Hassell, James Huddleston, Chris Mills, Matthew Moodie, Dominic Shakeshaft, Jim Sumser, Keir Thomas, Matt Wade Project Manager: Denise Santoro Lincoln Copy Edit Manager: Nicole Flores Copy Editor: Sharon Wilkey Assistant Production Director: Kari Brooks-Copony Production Editor: Lori Bring Compositor: Patrick Cunningham Proofreader: Dan Shaw Indexer: John Collin Artist: April Milne Cover Designer: Kurt Krames Manufacturing Director: Tom Debolski Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, email [email protected], or visit http://www.springeronline.com. For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley, CA 94710. Phone 510-549-5930, fax 510-549-5939, email [email protected], or visit http://www.apress.com. The information in this book is distributed on an “as is” basis, without warranty. Although every precau- tion has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. The source code for this book is available to readers at http://www.apress.com in the Source Code/ Download section as well as at http://www.integrallis.com. 7923FMCMP2 2/2/07 10:47 AM Page iii To the memory of my grandparents, Kasim Nusair and Kurdeih Rashdan; To my grandparents, Henry Albert Baker and Mary Baker; To my parents, Janette Darr and AJ Nusairat; And to all my friends and family who supported me throughout the years. 7923FMCMP2 2/2/07 10:47 AM Page iv 7923FMCMP2 2/2/07 10:47 AM Page v Contents at a Glance About the Author . xv About the Technical Reviewer . xvii Acknowledgments . xix Introduction . xxi ICHAPTER 1 What Is JBoss Seam? . 1 ICHAPTER 2 Web Applications . 23 ICHAPTER 3 JSF Fundamentals . 47 ICHAPTER 4 EJB3 Fundamentals . 85 ICHAPTER 5 Introduction to Seam . 121 ICHAPTER 6 Seam Contexts . 159 ICHAPTER 7 Business Process in Seam . 187 ICHAPTER 8 Advanced Topics. 223 ICHAPTER 9 Advanced Configurations . 269 ICHAPTER 10 Seam Tools . 287 IAPPENDIX A JBoss AS . 307 IAPPENDIX B JBoss IDE . 315 IFINAL THOUGHTS . 317 IINDEX . 319 v 7923FMCMP2 2/2/07 10:47 AM Page vi 7923FMCMP2 2/2/07 10:47 AM Page vii Contents About the Author . xv About the Technical Reviewer . xvii Acknowledgments . xix Introduction . xxi ICHAPTER 1 What Is JBoss Seam?. 1 What Does Seam Buy You? . 2 Three-Tier Architecture. 2 Three-Tier Architecture with Seam . 3 Component Choices . 4 Seam Environment Requirements . 6 Hello World Example. 7 Introduction to MVC Architecture . 9 Basics of MVC Architecture . 9 Frameworks . 10 Java 5 . 11 Downloading Java 5 . 12 Language Features . 14 POJOs . 20 Annotations on POJOs. 20 Configuring Your Server . 20 Summary. 21 ICHAPTER 2 Web Applications . 23 Servlets . 23 Contexts in Servlets. 24 Servlets and Frameworks. 25 vii 7923FMCMP2 2/2/07 10:47 AM Page viii viii ICONTENTS Implementation Patterns . 25 Understanding the Parts of Our Examples. 26 Displaying Dynamic Data . 28 Requesting and Saving Data . 30 Logging In . 34 Listing and Viewing a Page . 37 Sample Applications . 40 Garage Sale . 41 Travel Reservations . ..