Bauke Scholtz and

Arjan Tijms

The Definitive Guide to JSF in Java EE 8

Building Web Applications with JavaServer Faces

Bauke Scholtz

Willemstad, Curaçao

Arjan Tijms

Amsterdam, Noord-Holland, The Netherlands

Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub via the book’s product page, located at www.​apress.​com/​9781484233863 . For more detailed information, please visit http://​www.​apress.​com/​source-code .

ISBN 978-1-4842-3386-3

e-ISBN 978-1-4842-3387-0

https://doi.org/10.1007/978-1-4842-3387-0

Library of Congress Control Number: 2018942178

© Bauke Scholtz, Arjan Tijms 2018

This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed.

Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.

While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein.

Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.

To caffeine and our (not so) patient wives.

Table of Contents

  1. Chapter 1:​ History
    1. In the Beginning .​ .​ .​
    2. The Adolescent Years
    3. On to Maturity
    4. Rejuvenation
  2. Chapter 2:​ From Zero to Hello World
    1. Installing Java SE JDK
      1. What About Java EE?​
    2. Installing Payara
      1. How About Other Servers?​
    3. Installing Eclipse
      1. Configuring Eclipse
      2. Installing JBoss Tools Plug-in
      3. Integrating New Server in Eclipse
    4. Creating New Project in Eclipse
      1. Creating the Backing Bean Class
      2. Creating the Facelets File
      3. Deploying the Project
    5. Installing H2
      1. Configuring DataSource
      2. Configuring JPA
      3. Creating the JPA Entity
      4. Creating the EJB Service
      5. Adjusting the Hello World
  3. Chapter 3:​ Components
    1. Standard HTML Components
    2. Standard Core Tags
    3. Life Cycle
      1. Restore View Phase (First Phase)
      2. Apply Request Values Phase (Second Phase)
      3. Process Validations Phase (Third Phase)
      4. Update Model Values Phase (Fourth Phase)
      5. Invoke Application Phase (Fifth Phase)
      6. Render Response Phase (Sixth Phase)
    4. Ajax Life Cycle
    5. View Build Time
    6. View Render Time
    7. View State
    8. View Scope
    9. Phase Events
    10. Component System Events
    11. Custom Component System Events
    12. JSTL Core Tags
    13. Manipulating the Component Tree
  4. Chapter 4:​ Form Components
    1. Input, Select, and Command Components
    2. Text-Based Input Components
    3. File-Based Input Component
    4. Selection Components
    5. SelectItem Tags
    6. SelectItemGroup
    7. Label and Message Components
    8. Command Components
    9. Navigation
    10. Ajaxifying Components
    11. Navigation in Ajax
    12. GET forms
    13. Stateless Forms
  5. Chapter 5:​ Conversion and Validation
    1. Standard Converters
      1. <f:​convertNumber>
      2. <f:​convertDateTime>​
    2. Standard Validators
      1. <f:​validateLongRang​e>/​<f:​validateDoubleRa​nge>
      2. <f:​validateLength>/​<f:​validateRegex>
      3. <f:​validateRequired​>
      4. <f:​validateBean>/​<f:​validateWholeBea​n>
    3. Immediate Attribute
    4. Custom Converters
    5. Custom Validators
    6. Custom Constraints
    7. Custom Messages
  6. Chapter 6:​ Output Components
    1. Document-Based Output Components
    2. Text-Based Output Components
    3. Navigation-Based Output Components
    4. Panel-Based Output Components
    5. Data Iteration Component
      1. Editable <h:​dataTable>
      2. Add/​Remove Rows in <h:​dataTable>
      3. Select Rows in <h:​dataTable>
      4. Dynamic Columns in <h:​dataTable>
    6. Resource Components
    7. Pass-Through Elements
  7. Chapter 7:​ Facelets Templating
    1. XHTML
    2. Template Compositions
    3. Single Page Application
    4. Template Decorations
    5. Tag Files
    6. Composite Components
      1. Recursive Composite Component
    7. Implicit EL Objects
  8. Chapter 8:​ Backing Beans
    1. Model, View, or Controller?​
    2. Managed Beans
    3. Scopes
      1. @ApplicationScope​d
      2. @SessionScoped
      3. @ConversationScop​ed
      4. @FlowScoped
      5. @ViewScoped
      6. @RequestScoped
      7. @Dependent
    4. Which scope to choose?​
    5. Where Is @FlashScoped?​
    6. Managed bean initialization and destruction
    7. Injecting JSF vended types
    8. Eager Initialization
    9. Layers
    10. Naming Conventions
  9. Chapter 9:​ Exception Handling
    1. Custom Error Pages
    2. Ajax Exception Handling
    3. ViewExpiredExcep​tion Handling
    4. IOException Handling
    5. EJBException Handling
  10. Chapter 10:​ WebSocket Push
    1. Configuration
    2. Usage
    3. Scopes and Users
    4. Channel Design Hints
    5. One-Time Push
    6. Stateful UI Updates
    7. Site-Wide Push Notifications
    8. Keeping Track of Active Sockets
    9. Detecting Session and View Expiration
    10. Breaking Down Mojarra’s f:​websocket Implementation
  11. Chapter 11:​ Custom Components
    1. Component Type, Family, and Renderer Type
    2. Creating New Component and Renderer
    3. Extending Existing Component
    4. Extending Existing Renderer
    5. Custom Tag Handlers
    6. Packaging in a Distributable JAR
    7. Resource Dependencies
  12. Chapter 12:​ Search Expressions
    1. Relative Local IDs
    2. Absolute Hierarchical IDs
    3. Standard Search Keywords
    4. Custom Search Keywords
  13. Chapter 13:​ Security
    1. Java EE Security Overview and History
    2. Protect Access to Resources
      1. Excluded
      2. Unchecked
      3. By Role
    3. Setting the Authentication Mechanism
    4. Setting the Identity Store
    5. Providing Our Custom JSF Code
    6. Caller-Initiated Authentication
    7. Remember Me
      1. Activating Remember-Me Service
    8. Logging Out
    9. Custom Principals
    10. Conditionally Rendering Based on Access
    11. Cross-Site Request Forgery Protection
    12. Web Parameter Tampering Protection
    13. Cross-Site Scripting Protection
    14. Source Exposure Protection
  14. Chapter 14:​ Localization
    1. Hello World, Olá mundo, A454457_1_En_BookFrontmatter_Fige_HTML.gif
    2. Configuration
    3. Referencing Bundle in JSF Page
    4. Changing the Active Locale
    5. Organizing Bundle Keys
    6. Localizing Conversion/​Validation Messages
    7. Obtaining Localized Message in a Custom Converter/​Validator
    8. Localizing Enums
    9. Parameterized Resource Bundle Values
    10. Database-Based ResourceBundle
    11. HTML in ResourceBundle
  15. Chapter 15 :​ Extensions
    1. Extension Types
    2. Extending CDI Artifacts
    3. Extending Classical Artifacts
    4. Plug-ins
    5. Dynamic Extensions
      1. Application Configuration Populator
      2. The Application Main Class
    6. Local Extension and Wrapping
    7. Introspection
  16. Index

About the Authors and About the Technical Reviewer

About the Authors

A454457_1_En_BookFrontmatter_Figb_HTML.jpg

Bauke Scholtz is an Oracle Java Champion, a member of the JSF 2.3 Expert Group, and the main creator of the JSF helper library OmniFaces. On the Internet, he is more commonly known as BalusC, who is among the top users and contributors on Stack Overflow. Bauke has integrated several OmniFaces solutions into JSF 2.3. He is a web application specialist and consults or has consulted for Mercury1 Limited, MyTutor, Nava Finance, LinkPizza, ZEEF, M4N/Zanox, ITCA, RDC, and more clients from fintech, affiliate marketing, social media, and more as part of his 17 years of experience. This book offers Bauke the opportunity to go into depth to answer most frequently asked questions and correctly solve most commonly encountered problems while using JSF.

A454457_1_En_BookFrontmatter_Figc_HTML.jpg

Arjan Tijms works for Payara Services Ltd and is a JSF (JSR 372) and Security API (JSR 375) Expert Group member. He is the co-creator of the popular OmniFaces library for JSF, which was a 2015 Duke’s Choice Award winner, and is the main creator of a set of tests for the Java EE authentication SPI (JASPIC) used by various Java EE vendors. Arjan holds an MSc degree in Computer Science from the University of Leiden, The Netherlands. Writing about this topic was a natural choice for Arjan; He has already written much about it on his blog and wanted to expand that by contributing to a book.

About the Technical Reviewer

A454457_1_En_BookFrontmatter_Figd_HTML.jpg

Chád (“Shod”) Darby is an author, instructor, and speaker in the Java development world. As a recognized authority on Java applications and architectures, he has presented technical sessions at software development conferences worldwide (in the United States, UK, India, Russia, and Australia). In his 15 years as a professional software architect, he’s had the opportunity to work for Blue Cross/Blue Shield, Merck, Boeing, Red Hat, and a handful of startup companies.

Chád is a contributing author to several Java books, including Professional Java E-Commerce (Wrox Press), Beginning Java Networking (Wrox Press), and XML and Web Services Unleashed (Sams Publishing). Chád has Java certifications from Sun Microsystems and IBM. He holds a BS in computer science from Carnegie Mellon University. You can visit Chád’s blog at www.luv2code.com to view his free video tutorials on Java. You can also follow him on Twitter at @darbyluvs2code.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.48.78