ebook img

JSF 2.0 Cookbook PDF

396 Pages·2010·4.65 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview JSF 2.0 Cookbook

JSF 2.0 Cookbook Over 100 simple but incredibly effective recipes for taking control of your JSF applications Anghel Leonard BIRMINGHAM - MUMBAI JSF 2.0 Cookbook Copyright © 2010 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, Packt Publishing, nor its dealers or distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: June 2010 Production Reference: 1310610 Published by Packt Publishing Ltd. 32 Lincoln Road Olton Birmingham, B27 6PA, UK. ISBN 978-1-847199-52-2 www.packtpub.com Cover Image by Prasad Hamine ([email protected]) Credits Author Editorial Team Leader Anghel Leonard Mithun Sehgal Reviewer Project Team Leader Edem Morny Lata Basantani Acquisition Editor Project Coordinator Sarah Cullington Poorvi Nair Development Editor Proofreader Rakesh Shejwal Chris Smith Technical Editor Production Coordinator Arani Roy Shantanu Zagade Indexer Cover Work Hemangini Bari Shantanu Zagade About the Author Anghel Leonard is a senior Java developer with more than 12 years of experience in Java SE, Java EE, and the related frameworks. He has written and published more than 20 articles and 100 tips and tricks about Java technology. Also, he has written two books about XML and Java (one for beginners and one for advanced users) and another book for Packt Publishing, named JBoss Tools 3 Developer Guide. In this time, he has developed web applications using the latest technologies out in the market. In the past two years, he has focused on developing RIA projects for GIS fields. He is interested in bringing as much desktop to the Web as possible; as a result GIS applications present a real challenge to him. I would like to thank my family, especially, my wife! About the Reviewer Edem Morny has been involved in enterprise Java technologies since he got introduced to Java in 2005, using tools and technologies encompassing both the standard JavaEE stack and non-standard ones such as JBoss Seam, Hibernate, and Spring. His experience with JSF includes working with plain JSF, RichFaces, JBoss Seam, and Spring Web Flow's SpringFaces. He has been an active promoter of Java EE, speaking at workshops and seminars of a national scale in Ghana. He is a Senior Developer at the Application Development Center in Accra, Ghana, for an international biometric security solutions company, which is leading the development of Biocryptic Identity Management Systems for the global market. Edem was a technical reviewer for JBoss Tools 3 Developer Guide and JBoss AS 5 Development both published by Packt Publishing. You'll find him blogging at http://edemmorny.wordpress.com. Table of Contents Preface 1 Chapter 1: Using Standard and Custom Converters in JSF 7 Introduction 8 Working with implicit and explicit conversions 10 Standard converters for numbers 12 Standard converters for date and time 15 Converters and NULL values 19 Creating and using a custom converter 22 Using custom converters for h:selectOneMenu 25 Binding converters to backing bean properties 30 RichFaces and standard converters 32 RichFaces and custom converters 34 Instance variables in converters 36 Client-side converters with MyFaces Trinidad 40 Chapter 2: Using Standard and Custom Validators in JSF 51 Introduction 52 Using a standard validator 53 Customizing error messages for validators 55 Creating a custom validator 58 Binding validators to backing bean properties 61 Validating forms with RichFaces rich:beanValidator 63 Validating forms with RichFaces rich:ajaxValidator 65 Apache MyFaces Commons validators 67 Bean validation with f:validateBean 68 Enforcing a value's presence with f:validateRequired 76 Using regular expressions with f:validateRegex 78 Table of Contents Chapter 3: File Management 81 Introduction 81 Downloading files using Mojarra Scales 81 Multi-file upload using Mojarra Scales 85 File upload with Apache MyFaces Tomahawk 88 AJAX multi-file upload with RichFaces 93 Downloading with PrimeFaces 2.0 97 PPR multi-file upload with PrimeFaces 2.0 100 Extracting data from an uploaded CSV file 104 Exporting data to Excel, PDF, CVS, and XML 109 Chapter 4: Security 113 Introduction 113 Working with the JSF Security project 113 Using the JSF Security project without JAAS Roles 116 Using secured managed beans with JSF Security 121 Using Acegi/Spring security in JSF applications 123 Chapter 5: Custom Components 129 Introduction 129 Building a "HelloWorld" JSF custom component 131 Renderers/validators for custom components 138 Adding AJAX support to JSF custom components 144 Using Proxy Id library for dynamic IDs 161 Using JSF ID Generator 163 Accessing resources from custom components 167 Custom components with Archetypes for Maven 169 RichFaces CDK and custom components 173 Composite custom components with zero Java 187 Creating a login composite component in JSF 2.0 190 Building a spinner composite component in JSF 2.0 193 Mixing JSF and Dojo widget for custom components 195 Chapter 6: AJAX in JSF 201 Introduction 201 A first JSF 2.0-AJAX example 201 Using the f:ajax tag 204 Installing and using Dynamic Faces in NetBeans 6.8 205 Using the inputSuggestAjax component 208 ajax4jsf—more than 100 AJAX components 211 Writing reusable AJAX components in JSF 2.0 221 PrimeFaces, CommandLink, and CommandButton 223 ii Table of Contents Chapter 7: Internationalization and Localization 229 Introduction 229 Loading message resource bundles in JSF 230 Using locales and message resource bundles 231 Message resource bundles without f:loadBundle 233 Working with parameterized messages 234 Accessing message resource keys from a class 236 Providing a theme to a Visual Web JSF Project 240 Displaying Arabic, Chinese, Russian, and so on 241 Selecting a time zone in JSF 2.0 242 Chapter 8: JSF, Images, CSS, and JS 243 Introduction 244 Injecting CSS in JSF 244 JSF, CSS, and tables 246 JSF and dynamic CSS 248 Integrating JavaScript and JSF 251 Getting a JSF inputText value from JavaScript 253 Working with JSF hidden fields from JavaScript 254 Passing parameters from JS to JSF (client to server) 256 Passing parameters from JSF to JS (server to client) 257 Opening a pop-up window using JSF and JS 258 Passing parameters with HTTP GET within the URL 260 Communication between parent pop-up windows 262 Populating a JS load function with JSF values 267 Dynamic images with PrimeFaces 269 Cropping images with PrimeFaces 270 Working with rss4jsf project 273 Using resource handlers 275 Chapter 9: JSF—Managing and Testing 279 Introduction 279 Managing JSF with Faces Console 279 Testing JSF applications with JSFUnit 283 JSFUnit and Ant 289 JSFUnit API 292 A JSF and JMeter issue 295 Working with JSF Chart Creator 297 Chapter 10: Facelets 301 Introduction 301 Installing Facelets under JSF 1.2 (or JSF 1.1) 302 Facelets aliasing components 303 iii

Description:
This book, as the description says is aimed at developers with existing Java programming knowledge but I think the downloadable examples can make it useful to a wider audience as well. I would also like to recommend this book to anybody who is interested in what can be achieved server side, very qui
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.