You are previewing JavaServer Faces.
O'Reilly logo
JavaServer Faces

Book Description

JavaServer Faces, or JSF, brings a component-based model to web application development that's similar to the model that's been used in standalone GUI applications for years. The technology builds on the experience gained from Java Servlets, JavaServer Pages, and numerous commercial and open source web application frameworks that simplify the development process. In JavaServer Faces, developers learn how to use this new framework to build real-world web applications. The book contains everything you'll need: how to construct the HTML on the front end; how to create the user interface components that connect the front end to your business objects; how to write a back-end that's JSF-friendly; and how to create the deployment descriptors that tie everything together. JavaServer Faces pays particular attention to simple tasks that are easily ignored, but crucial to any real application: working with tablular data, for example, or enabling and disabling buttons. And this book doesn't hide from the trickier issues, like creating custom components or creating renderers for different presentation layers. Whether you're experienced with JSF or a just starting out, you'll find everything you need to know about this technology in this book. Topics covered include:

  • The JSF environment

  • Creating and rendering components

  • Validating input

  • Handling user-generated events

  • Controlling page navigation

  • Working with tabular data

  • Internationalization

  • Integration between JSF and Struts

  • Developing custom renderers and custom components

JavaServer Faces is a complete guide to the crucial new JSF technology. If you develop web applications, JSF belongs in your toolkit, and this book belongs in your library.

Table of Contents

  1. JavaServer Faces
    1. SPECIAL OFFER: Upgrade this ebook with O’Reilly
    2. A Note Regarding Supplemental Files
    3. Preface
      1. In This Book
      2. Audience
        1. What You Need to Know
      3. Organization
      4. About the Examples
      5. Conventions Used in This Book
      6. How to Contact Us
      7. Acknowledgments
    4. 1. Introducing JavaServer Faces
      1. 1.1. What Is JavaServer Faces?
      2. 1.2. How Does JSF Compare to Traditional Technologies?
        1. 1.2.1. Less Code in the User Interface Templates
        2. 1.2.2. More Modular User Interface Code
      3. 1.3. Where Does JSF Fit in the Big Picture?
        1. 1.3.1. Using JSF with JSP
        2. 1.3.2. Using JSF with Struts and Other Application Frameworks
        3. 1.3.3. Using JSF with Enterprise JavaBeans
      4. 1.4. What You Need to Get Started
    5. 2. JSF Development Process Overview
      1. 2.1. Developing an Application with a JSF-Based User Interface
      2. 2.2. Developing the Application Backend
      3. 2.3. Developing Components and Integration Code
      4. 2.4. Developing the User Interface Pages
    6. 3. Setting Up the JSF Environment
      1. 3.1. Installing the Java Software Development Kit
      2. 3.2. Installing the Tomcat Server
        1. 3.2.1. Windows Platforms
        2. 3.2.2. Unix Platforms (Including Linux and Mac OS X)
      3. 3.3. Testing Tomcat
      4. 3.4. Installing the Book Examples
      5. 3.5. Example Web Application Overview
    7. 4. Servlet and JavaServer Pages Basics
      1. 4.1. HTTP
        1. 4.1.1. Requests in Detail
        2. 4.1.2. Responses in Detail
        3. 4.1.3. Request Parameters
        4. 4.1.4. Request Methods
      2. 4.2. Web Application Deployment and Runtime Environment
        1. 4.2.1. Web Containers and Servlet Contexts
      3. 4.3. Servlets, Filters, and Listeners
        1. 4.3.1. Using Request Data
        2. 4.3.2. Compiling, Installing, and Running a Servlet
        3. 4.3.3. Generating Responses of Different Types
        4. 4.3.4. Filters and Listeners
          1. 4.3.4.1. Filters
          2. 4.3.4.2. Listeners
      4. 4.4. JavaServer Pages
        1. 4.4.1. JSP Processing
        2. 4.4.2. JSP Elements
          1. 4.4.2.1. Directive elements
          2. 4.4.2.2. Action elements
          3. 4.4.2.3. Scripting elements
          4. 4.4.2.4. Expression Language expressions
          5. 4.4.2.5. JSP comments
        3. 4.4.3. Creating, Installing, and Running a JSP Page
      5. 4.5. Accessing Application Data
    8. 5. Developing the Business Logic and Setting Up Authentication
      1. 5.1. Sample Application Overview
      2. 5.2. Implementing the Business Logic Classes
        1. 5.2.1. The ReportEntry Class
        2. 5.2.2. The Report Class
        3. 5.2.3. The ReportRegistry and FileReportRegistry Classes
      3. 5.3. Authentication and Authorization
        1. 5.3.1. Authenticating the User
        2. 5.3.2. Controlling Access to Web Resources
    9. 6. Creating and Rendering Components
      1. 6.1. The Basics
        1. 6.1.1. Using JSF Components in a JSP Page
        2. 6.1.2. Creating JSF Components
        3. 6.1.3. Rendering the View
        4. 6.1.4. Saving the View State
        5. 6.1.5. Installing and Configuring a JSF Web Application
        6. 6.1.6. Running a JSP Page Containing JSF Components
      2. 6.2. Binding Components to Model Properties
        1. 6.2.1. Using JSF EL Expressions
        2. 6.2.2. Using Value Binding Expressions
        3. 6.2.3. Converting Between Model and View Data Formats
        4. 6.2.4. Creating Objects Automatically as They Are Needed
      3. 6.3. Conditionally Render Components
        1. 6.3.1. Conditionally Disable Components Using Bean Properties
        2. 6.3.2. Conditionally Include Components Using Bean Properties
    10. 7. Validating Input
      1. 7.1. Dealing with Syntax Errors in User Input
      2. 7.2. Using the Standard Validators
        1. 7.2.1. Value Bindings for the Report Entry Fields
      3. 7.3. Defining Custom Error Messages
      4. 7.4. Using a Custom Validator
        1. 7.4.1. Registering a Custom Validator
        2. 7.4.2. Using a Custom Validator in a JSP Page
        3. 7.4.3. Developing a Validator Custom Action
        4. 7.4.4. Deploying the Custom Tag Library
        5. 7.4.5. An Alternative for the Lazy
      5. 7.5. Other Ways to Validate Input
    11. 8. Handling Events
      1. 8.1. Understanding the JSF Event Model
        1. 8.1.1. The Request Processing Lifecycle Phases
      2. 8.2. Handling Application Backend Events
        1. 8.2.1. Using an Action Method and the Default ActionListener
        2. 8.2.2. Using an Action Listener Method or Instance
        3. 8.2.3. Specifying When to Fire an Event
      3. 8.3. Handling User Interface Events
        1. 8.3.1. Triggering an Event by Clicking a Button or a Link
        2. 8.3.2. Triggering an Event by Changing a Value
    12. 9. Controlling Navigation
      1. 9.1. Moving Between JSF Views
        1. 9.1.1. Choosing Between Redirect and Direct Rendering
        2. 9.1.2. Using a Panel Component for Layout
      2. 9.2. Returning a Non-JSF View Response
        1. 9.2.1. Linking Non-JSF Resources
        2. 9.2.2. Processing JSF Input and Generating a Non-JSF Response
      3. 9.3. Returning a JSF View Response to a Non-JSF Request
    13. 10. Working with Tabular Data
      1. 10.1. Displaying a Read-Only Table
        1. 10.1.1. Using Facets
        2. 10.1.2. A Word About JSF and Databases
      2. 10.2. Processing Row-Specific Events
      3. 10.3. Dealing with Large Tables
        1. 10.3.1. Sorting the Data
        2. 10.3.2. Scrolling Through the Data
        3. 10.3.3. Giving the Table Some Style
      4. 10.4. Editing Tabular Data
    14. 11. Internationalization
      1. 11.1. Localizing Application Output
        1. 11.1.1. Selecting Localized Text
        2. 11.1.2. Formatting Dates and Numbers
        3. 11.1.3. Localizing Messages
      2. 11.2. Handling Localized Application Input
      3. 11.3. Dealing with Non-Western Languages
    15. 12. Odds and Ends
      1. 12.1. Building a View from Many JSP Files
        1. 12.1.1. Using Static Includes for Pages with JSF Components
          1. 12.1.1.1. Using one or multiple forms
          2. 12.1.1.2. The included files
        2. 12.1.2. Using Dynamic Includes for Pages with JSF Components
          1. 12.1.2.1. Naming containers for included content
      2. 12.2. Combining JSF Views with Other Content
      3. 12.3. Dealing with Struts Applications and JSF
        1. 12.3.1. Using the Struts-Faces Integration Package
        2. 12.3.2. Migrating a Struts Application to JSF
        3. 12.3.3. Picking the Right Technology for a New Application
      4. 12.4. Programmatically Modifying Components
      5. 12.5. Using a PhaseListener
      6. 12.6. Debugging and Error Handling Ideas
        1. 12.6.1. Using Standard Java Debugging Techniques
        2. 12.6.2. Using Standard Web Application Error Handling
        3. 12.6.3. Using Client-Side State Saving During Development
        4. 12.6.4. Capturing State with a PhaseListener
    16. 13. Developing Custom Renderers and Other Pluggable Classes
      1. 13.1. Developing Custom Renderers
        1. 13.1.1. A Renderer for Encoding Only
          1. 13.1.1.1. The Renderer class
          2. 13.1.1.2. Registering the renderer
          3. 13.1.1.3. The JSP tag handler class
          4. 13.1.1.4. Using the custom renderer
        2. 13.1.2. A Renderer for Encoding and Decoding
          1. 13.1.2.1. The Renderer class
          2. 13.1.2.2. Registering the renderer
          3. 13.1.2.3. The JSP tag handler class
      2. 13.2. Using Other Custom Classes
      3. 13.3. Packaging Custom Classes
    17. 14. Developing Custom Components
      1. 14.1. Extending an Existing Component
        1. 14.1.1. The TabbedRenderer Class
        2. 14.1.2. The UITabLabel Class
        3. 14.1.3. Registering the Component
        4. 14.1.4. The JSP Tag Handler Class
      2. 14.2. Developing a New Component from Scratch
        1. 14.2.1. The TreeModel Class
        2. 14.2.2. The UITree Component Class
        3. 14.2.3. The TreeRenderer Class
        4. 14.2.4. Registering the Component and the Renderer
        5. 14.2.5. The JSP Tag Handler Class
    18. 15. Developing a Custom Presentation Layer
      1. 15.1. The ViewHandler Class
      2. 15.2. Using Java Classes as Views
        1. 15.2.1. Developing the View Class
        2. 15.2.2. Developing the ViewHandler
      3. 15.3. Using Pure HTML Templates with XML View Definition Files
        1. 15.3.1. Developing the HTML Template and the View Specification
        2. 15.3.2. Developing the ViewHandler
    19. A. Standard JSF Tag Libraries
      1. A.1. JSF Tag Libraries URIs and Default Prefixes
      2. A.2. HTML Tag Library Actions
        1. A.2.1. Supported HTML 4.01 Attributes
          1. <h:column>
          2. <h:commandButton>
          3. <h:commandLink>
          4. <h:dataTable>
          5. <h:form>
          6. <h:graphicImage>
          7. <h:inputHidden>
          8. <h:inputSecret>
          9. <h:inputText>
          10. <h:inputTextarea>
          11. <h:message>
          12. <h:messages>
          13. <h:outputFormat>
          14. <h:outputLabel>
          15. <h:outputLink>
          16. <h:outputText>
          17. <h:panelGrid>
          18. <h:panelGroup>
          19. <h:selectBooleanCheckbox>
          20. <h:selectManyCheckbox>
          21. <h:selectManyListbox>
          22. <h:selectManyMenu>
          23. <h:selectOneListbox>
          24. <h:selectOneMenu>
          25. <h:selectOneRadio>
      3. A.3. Core Library Actions
        1. <f:actionListener>
        2. <f:attribute>
        3. <f:convertDateTime>
        4. <f:convertNumber>
        5. <f:converter>
        6. <f:facet>
        7. <f:loadBundle>
        8. <f:param>
        9. <f:selectItem>
        10. <f:selectItems>
        11. <f:subView>
        12. <f:validateDoubleRange>
        13. <f:validateLength>
        14. <f:validateLongRange>
        15. <f:validator>
        16. <f:valueChangeListener>
        17. <f:verbatim>
        18. <f:view>
    20. B. JSF Expression Language Reference
      1. B.1. Syntax
        1. B.1.1. Literals
        2. B.1.2. Keywords and Reserved Words
      2. B.2. Variables
        1. B.2.1. Implicit Variables
      3. B.3. Data Types
        1. B.3.1. Coercion Rules
      4. B.4. Expressions and Operators
        1. B.4.1. Operand Evaluation and Coercing Rules
          1. B.4.1.1. Property and array accessor operators
          2. B.4.1.2. Arithmetic operators
          3. B.4.1.3. Relational operators
          4. B.4.1.4. Logical operators
          5. B.4.1.5. Empty operator
    21. C. Standard JSF Components and Render Kits
      1. C.1. Component Class Categories
      2. C.2. Render-Independent Components
        1. C.2.1. Component Interfaces
          1. ActionSource
          2. EditableValueHolder
          3. NamingContainer
          4. StateHolder
          5. ValueHolder
        2. C.2.2. Component Classes
          1. UIColumn
          2. UICommand
          3. UIComponent and UIComponentBase
          4. UIData
          5. UIForm
          6. UIGraphic
          7. UIInput
          8. UIMessage
          9. UIMessages
          10. UINamingContainer
          11. UIOutput
          12. UIPanel
          13. UIParameter
          14. UISelectBoolean
          15. UISelectItem
          16. UISelectItems
          17. UISelectMany
          18. UISelectOne
          19. UIViewRoot
        3. C.2.3. Model Classes and Interfaces
          1. ArrayDataModel
          2. DataModel
          3. DataModelEvent
          4. DataModelListener
          5. ListDataModel
          6. ResultDataModel
          7. ResultSetDataModel
          8. ScalarDataModel
          9. SelectItem
          10. SelectItemGroup
      3. C.3. HTML Render Kit Classes
        1. C.3.1. Renderer Class
          1. Renderer
        2. C.3.2. Standard Renderer Behavior
          1. Command/Button
          2. Command/Link
          3. Data/Table
          4. Form/Form
          5. Graphic/Image
          6. Input/Hidden
          7. Input/Secret
          8. Input/Text
          9. Input/Textarea
          10. Message/Message
          11. Messages/Messages
          12. Output/Format
          13. Output/Label
          14. Output/Link
          15. Output/Text
          16. Panel/Grid
          17. Panel/Group
          18. SelectBoolean/Checkbox
          19. SelectMany/Checkbox
          20. SelectMany/Listbox
          21. SelectMany/Menu
          22. SelectOne/Listbox
          23. SelectOne/Menu
          24. SelectOne/Radio
      4. C.4. HTML-Specific Component Classes
        1. HtmlCommandButton
        2. HtmlCommandLink
        3. HtmlDataTable
        4. HtmlForm
        5. HtmlGraphicImage
        6. HtmlInputHidden
        7. HtmlInputSecret
        8. HtmlInputText
        9. HtmlInputTextarea
        10. HtmlMessage
        11. HtmlMessages
        12. HtmlOutputFormat
        13. HtmlOutputLabel
        14. HtmlOutputLink
        15. HtmlOutputText
        16. HtmlPanelGrid
        17. HtmlPanelGroup
        18. HtmlSelectBooleanCheckbox
        19. HtmlSelectManyCheckbox
        20. HtmlSelectManyListbox
        21. HtmlSelectManyMenu
        22. HtmlSelectOneListbox
        23. HtmlSelectOneMenu
        24. HtmlSelectOneRadio
      5. C.5. Request Processing Lifecycle
        1. C.5.1. Restore View
        2. C.5.2. Apply Request Values
        3. C.5.3. Process Validations
        4. C.5.4. Update Model Values
        5. C.5.5. Invoke Application
        6. C.5.6. Render Response
    22. D. Infrastructure API Reference
      1. D.1. Package javax.faces
        1. FacesException
        2. FactoryFinder
      2. D.2. Package javax.faces.application
        1. Application
        2. ApplicationFactory
        3. FacesMessage
        4. FacesMessage.Severity
        5. NavigationHandler
        6. StateManager
        7. StateManager.SerializedView
        8. ViewHandler
      3. D.3. Package javax.faces.context
        1. ExternalContext
        2. FacesContext
        3. FacesContextFactory
        4. ResponseStream
        5. ResponseWriter
      4. D.4. Package javax.faces.convert
        1. BigDecimalConverter
        2. BigIntegerConverter
        3. BooleanConverter
        4. ByteConverter
        5. CharacterConverter
        6. Converter
        7. ConverterException
        8. DateTimeConverter
        9. DoubleConverter
        10. FloatConverter
        11. IntegerConverter
        12. LongConverter
        13. NumberConverter
        14. ShortConverter
      5. D.5. Package javax.faces.el
        1. EvaluationException
        2. MethodBinding
        3. MethodNotFoundException
        4. PropertyNotFoundException
        5. PropertyResolver
        6. ReferenceSyntaxException
        7. ValueBinding
        8. VariableResolver
      6. D.6. Package javax.faces.event
        1. AbortProcessingException
        2. ActionEvent
        3. ActionListener
        4. FacesEvent
        5. FacesListener
        6. PhaseEvent
        7. PhaseId
        8. PhaseListener
        9. ValueChangeEvent
        10. ValueChangeListener
      7. D.7. Package javax.faces.lifecycle
        1. Lifecycle
        2. LifecycleFactory
      8. D.8. Package javax.faces.render
        1. Renderer
        2. RenderKit
        3. RenderKitFactory
        4. ResponseStateManager
      9. D.9. Package javax.faces.validator
        1. DoubleRangeValidator
        2. LengthValidator
        3. LongRangeValidator
        4. Validator
        5. ValidatorException
      10. D.10. Package javax.faces.webapp
        1. AttributeTag
        2. ConverterTag
        3. FacesServlet
        4. FacetTag
        5. UIComponentBodyTag
        6. UIComponentTag
        7. ValidatorTag
      11. D.11. Identifiers for Standard JSF Messages
        1. javax.faces.component.UIInput.CONVERSION
        2. javax.faces.component.UIInput.REQUIRED
        3. javax.faces.component.UISelectOne.INVALID
        4. javax.faces.component.UISelectMany.INVALID
        5. javax.faces.validator.NOT_IN_RANGE
        6. javax.faces.validator.DoubleRangeValidator.MAXIMUM
        7. javax.faces.validator.DoubleRangeValidator.MINIMUM
        8. javax.faces.validator.DoubleRangeValidator.TYPE
        9. javax.faces.validator.LengthRangeValidator.MAXIMUM
        10. javax.faces.validator.LengthRangeValidator.MINIMUM
        11. javax.faces.validator.LengthRangeValidator.TYPE
        12. javax.faces.validator.LongRangeValidator.MAXIMUM
        13. javax.faces.validator.LongRangeValidator.MINIMUM
        14. javax.faces.validator.LongRangeValidator.TYPE
    23. E. JSF Configuration File Reference
      1. <description>, <display-name>, and <icon>
      2. <application>
      3. <factory>
      4. <component>
      5. <converter>
      6. <lifecycle>
      7. <managed-bean>
      8. <navigation-rule>
      9. <referenced-bean>
      10. <render-kit>
      11. <validator>
    24. F. Web Application Structure and Deployment Descriptor Reference
      1. F.1. Web Application File Structure
        1. F.1.1. Placing Java Class Files in the Right Directory
      2. F.2. Web Application Deployment Descriptor
        1. Reference Section
          1. <description>, <display-name>, and <icon>
        2. Reference Section
          1. <distributable>
        3. Reference Section
          1. <context-param>
        4. Reference Section
          1. <filter>
        5. Reference Section
          1. <filter-mapping>
        6. Reference Section
          1. <listener>
        7. Reference Section
          1. <servlet>
        8. Reference Section
          1. <servlet-mapping>
        9. Reference Section
          1. <session-config>
        10. Reference Section
          1. <mime-mapping>
        11. Reference Section
          1. <welcome-file-list>
        12. Reference Section
          1. <error-page>
        13. Reference Section
          1. <jsp-config>
        14. Reference Section
          1. <resource-env-ref>
        15. Reference Section
          1. <resource-ref>
        16. Reference Section
          1. <security-constraint>
        17. Reference Section
          1. <login-config>
        18. Reference Section
          1. <security-role>
        19. Reference Section
          1. <locale-encoding-mapping-list>
        20. Reference Section
          1. <env-entry>
        21. Reference Section
          1. <ejb-ref>
        22. Reference Section
          1. <ejb-local-ref>
        23. Reference Section
          1. <service-ref>
        24. Reference Section
          1. <message-destination-ref>
        25. Reference Section
          1. <message-destination>
        26. F.2.1. Example Application Deployment Descriptor
      3. F.3. Creating a WAR File
    25. About the Author
    26. Colophon
    27. SPECIAL OFFER: Upgrade this ebook with O’Reilly