O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Apache MyFaces 1.2

Book Description

Building next-generation web applications with JSF and Facelets

  • Build powerful and robust web applications with Apache MyFaces

  • Reduce coding by using sub-projects of MyFaces like Trinidad, Tobago, and Tomahawk

  • Update the content of your site daily with ease by using Facelets

  • Step-by-step and practical tutorial with lots of examples

  • In Detail

    Hypes and trends (such as Web 2.0) cause a change in the requirements for user interfaces every now and then. While a lot of frameworks are capable of meeting those changing requirements, it often means you as a developer need in-depth knowledge of web standards, such as XHTML and JavaScript. A framework like Apache MyFaces that hides all details of how the page is rendered at the client and at the same time offers a rich set of tools and building blocks could save you a lot of time, not only when you're building a brand new application but also when you're adapting an existing application to meet new user interface requirements.

    This book will teach you everything you need to know to build appealing web interfaces with Apache MyFaces and maintain your code in a pragmatic way. It describes all the steps that are involved in building a user interface with Apache MyFaces. This includes building templates and composition components with Facelets, using all sorts of specialized components from the Tomahawk, Trinidad, and Tobago component sets and adding validation with MyFaces Extensions Validator.

    The book uses a step-by-step approach and contains a lot of tips based on experience of the MyFaces libraries in real-world projects. Throughout the book an example scenario is used to work towards a fully functional application when the book is finished.

    This step-by-step guide will help you to build a fully functional and powerful application.

    This book will teach you everything you need to know in order to build appealing web interfaces with Apache MyFaces in a pragmatic way.

    Table of Contents

    1. Apache MyFaces 1.2
    2. Credits
    3. About the Author
    4. Acknowledgement
    5. About the Reviewers
    6. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Errata
        2. Piracy
        3. Questions
    7. 1. Introduction
      1. Introducing Apache MyFaces
        1. License, community, and support
        2. MyFaces and Sun JSF RI
      2. Subprojects of Apache MyFaces
        1. Core
        2. Tomahawk
        3. Sandbox
        4. Trinidad
        5. Tobago
        6. Orchestra
        7. Portlet Bridge
        8. Extensions Validator
      3. Summary
    8. 2. Getting Started
      1. Configuring the development environment
        1. Configuring Eclipse
          1. Installing extra plugins
          2. Installing the libraries
          3. Preparing a new project
        2. Configuring JDeveloper
          1. Installing the libraries
          2. Preparing a new project
        3. Creating a new project using Maven
      2. Application server and configuration files
        1. The web.xml configuration file
        2. The faces-config.xml configuration file
        3. Settings for specific application servers
          1. Settings for MyFaces Core on GlassFish
          2. Other application servers
      3. Introduction to the example case
      4. Summary
    9. 3. Facelets
      1. Why Facelets?
        1. Content inverweaving
        2. Templating
        3. Don’t Repeat Yourself (DRY)
        4. Expanding the Expression Language
        5. Summarizing the benefits of Facelets
      2. Setting up a Facelets project
        1. Preparing web.xml
        2. Preparing faces-config.xml
        3. Creating a test page
        4. Debugging easily with Facelets
      3. Templating with Facelets
        1. Creating a template
        2. Using the template
        3. Using comments in Facelets page definitions
        4. Are Facelets files XHTML?
      4. Creating and using composition components
        1. Creating a tag library
        2. Creating the composition component itself
          1. Identifying redundancies
          2. Creating a skeleton for the composition component
          3. Defining the actual composition component
          4. Adding validators without violating the DRY principle
          5. Putting it all together
        3. Using the composition component
      5. Using static functions
      6. Using inline texts
      7. Facelets tags overview
        1. <ui:component> tag
        2. <ui:composition> tag
        3. <ui:debug> tag
        4. <ui:decorate> tag
        5. <ui:define> tag
        6. <ui:fragment> tag
        7. <ui:include> tag
        8. <ui:insert> tag
        9. <ui:param> tag
        10. <ui:remove> tag
        11. <ui:repeat> tag
      8. Summary
    10. 4. Tomahawk
      1. Setting up Tomahawk
        1. Downloading Tomahawk
        2. Configuring web.xml
        3. Resolving dependencies
      2. Using extended versions of standard components
      3. Extended components
        1. <t:aliasBean> and <t:aliasBeanScope> components
        2. <t:buffer>
        3. <t:captcha> component
      4. Creating basic data tables
        1. Setting up a data table
        2. Adding columns to the table
        3. Using pagination
        4. Changing the looks of the data table
          1. Styling the data table itself
          2. Styling the data scroller
          3. Looking at the result
      5. Using advanced data table features
        1. Sorting
          1. Improving the sort arrows
        2. Showing details inline
        3. Linking to an edit form
        4. Grouping rows
        5. Newspaper columns
      6. Uploading files
      7. Working with dates and calendars
        1. Using a pop-up calendar
          1. Localizing the pop-up calendar
        2. Using an inline calendar
        3. Using the calendar in a form
      8. Extra validators
        1. Validating equality
        2. Validating e-mail addresses
        3. Validating credit card numbers
        4. Validating against a pattern
      9. Summary
    11. 5. Trinidad&mdash;the Basics
      1. Setting up Trinidad
        1. Configuring the web.xml file
        2. Configuring the faces-config.xml file
        3. Configuring the trinidad-config.xml file
        4. Adapting our template
      2. Creating data tables
        1. Adding columns
        2. Using pagination
        3. Displaying inline details
        4. Configuring banding and grid lines
        5. Using row selection
      3. Creating input and edit forms
        1. Exploring the common features of input components
          1. Using automatic label rendering
          2. Using error message support and the required indicator
          3. Using auto submit
        2. Creating plain text input fields
          1. Using the <tr:inputText> component in a composition component
        3. Creating date input fields
          1. Converting dates
          2. Validating dates
          3. Creating the ultimate date input composition component
        4. Creating selection lists
          1. Adding list contents
          2. Optional empty selection for single selection lists
          3. Options for all selection components
          4. Checkboxes and radio buttons
          5. Listboxes
          6. Choice list
          7. Shuttle
          8. Ordering shuttle
          9. Creating a universal composition component for selections
        5. Creating fields for numerical input
          1. Adding conversion to a field
          2. Adding validation to a field
          3. Adding a spin box to an input field
      4. File uploading
        1. Meeting the prerequisites
        2. Using the file upload component
          1. Creating and using a file upload composition component
          2. Saving the file in the backing bean
        3. Configuring file upload limits
          1. Setting upload limits in web.xml
          2. Setting upload limits in trinidad-config.xml
      5. Using Trinidad’s hierarchical navigation features
        1. Configuring the hierarchy
        2. Creating navigation panes
        3. Creating breadcrumbs
        4. Creating a hierarchical menu
      6. Creating layouts for our pages
        1. Using a border layout
          1. Layout methods
        2. Using group layout
        3. Using a horizontal layout
        4. Creating layouts for input forms
          1. Grouping components
          2. Label and message
          3. Footer facet
        5. Creating an accordion
        6. Creating a tabbed panel
        7. Creating a choice panel
        8. Creating a radio panel
        9. Displaying boxes
        10. Displaying tips
        11. Using a header panel
        12. Using pop ups
        13. Creating button bars
        14. Using caption groups
        15. Creating bulleted lists
        16. Lay out a page by using the panel page component
        17. Using the page header panel
      7. Summary
    12. 6. Advanced Trinidad
      1. Data visualization
        1. Creating the data model
          1. Understanding the terminology
          2. Implementing a minimal data model
          3. Calculating the values
        2. Initializing the data model
        3. Adding a graph to a page
          1. Changing data display
          2. Changing the looks
        4. Chart types
        5. Some final thoughts on data visualization
      2. Passing on data with page flows
      3. Using AJAX and Partial Page Rendering
        1. Comparing full submit and partial submit
        2. Using the autoSubmit and partialTriggers attributes
        3. Working with partialTriggers and naming containers
        4. Creating a status indicator
        5. Using the addPartialTarget() method
        6. Dynamically hiding or showing components
        7. Polling
        8. Exploring the possibilities of PPR
      4. Creating dialogs
        1. Building a dialog
          1. Creating the backing bean for the dialog
          2. Using an alternative way of returning values
        2. Calling the dialog
        3. Receiving the dialog’s output
        4. Using inputListOfValues as an easier alternative
        5. Using lightweight dialogs
      5. Client-side validation and conversion
        1. Defining the data structure
        2. Creating the converter
        3. Enabling client-side capabilities
          1. Implementing the client-side code
        4. Creating the validator
          1. Enabling client-side capabilities
          2. Implementing the client-side code
        5. Wiring everything together
          1. Declaring the converter and validator in faces-config.xml
          2. Creating custom tags
          3. Using the converter and validator in a page
        6. Internationalization of messages
          1. Changing getClientValidator()
          2. Changing the JavaScript constructor
          3. Formatting the error message
        7. Using Trinidad’s JavaScript API
        8. Writing, testing, and debugging JavaScript
          1. Writing JavaScript code
          2. Debugging
          3. Logging
      6. Summary
    13. 7. Trinidad Skinning and Tuning
      1. Skinning
        1. Understanding the terminology
        2. Setting up skinning
          1. Letting the user choose the skin
        3. Creating a Trinidad skin
          1. Skinning components
          2. Using component state selectors
          3. Using component piece selectors
          4. Setting global styles using alias selectors
          5. Skinning icons
          6. Skinning text
        4. Extending skins
      2. Tuning Trinidad
        1. trinidad-config.xml file
        2. web.xml file
        3. Accessibility
          1. Accessibility mode (T)
          2. Accessibility profile (T)
          3. Lightweight dialogs (W)
        4. Performance
          1. Page flow scope lifetime (T)
          2. Uploaded file processor (T)
          3. State saving (W)
          4. Application view caching (W)
        5. Debugging
          1. Enabling debug output (T)
          2. Turning off compression and obfuscation (W)
          3. Changing deployed files (W)
        6. Appearance
          1. Client validation (T)
          2. Output mode (T)
          3. Skin family (T)
        7. Localization
          1. Time zone (T)
          2. Two-digit year start (T)
          3. Reading direction (T)
          4. Number notation (T)
      3. Summary
    14. 8. Integrating with the Backend
      1. The Model-View-Controller architecture
      2. Setting up the Java EE application structure
        1. Creating a skeleton EJB JAR
        2. Creating an EAR to wrap them all
      3. Preparing a database environment
        1. Creating a database
        2. Connecting to the database
        3. Managing the database
        4. Creating a table for employees
          1. Populating the table with data
      4. Implementing the Model
        1. Creating an entity
        2. Creating a service facade
        3. Creating named queries
        4. Defining persistence units
        5. Defining a data source
      5. Using the service facade in the View layer
        1. Updating the pages
      6. Limitations and problems
        1. Transactions
        2. Validation of data
      7. Summary
    15. 9. MyFaces Orchestra
      1. Setting up Orchestra
        1. Adapting the application structure
        2. Downloading the Spring framework
        3. Configuring Spring
          1. Letting Spring manage the beans
          2. Configuring the faces-config.xml file for Spring
          3. Configuring the web.xml file for Spring
          4. Configuring Spring and persistence
          5. Accessing the services
        4. Downloading and installing Orchestra
        5. Configuring Orchestra
      2. Using the Orchestra ViewController
        1. Using event methods
      3. Setting up Orchestra conversations
        1. Creating a conversation
        2. Extending the conversation
        3. Ending the conversation
      4. Generating forms with DynaForm
        1. Installing DynaForm
        2. Using DynaForm
      5. Summary
    16. 10. Extensions Validator
      1. Setting up ExtVal
      2. Basic usage
      3. Complementing JPA annotations
        1. Using ExtVal annotations for standard JSF validators
          1. Defining length validation
          2. Defining double range validation
          3. Defining long range validation
          4. Defining required fields
        2. Using ExtVal’s additional annotations
          1. Defining pattern-based validation
          2. Using custom validators
        3. Reusing validation
      4. Applying cross validation
        1. Using cross validation for date values
        2. Using cross validation based on equality
        3. Making a value required conditionally
      5. Creating custom error messages
        1. Overriding standard JSF error messages
        2. Overriding ExtVal default error messages
      6. Creating our own validation strategy
        1. Implementing a custom validation strategy
        2. Configuring ExtVal to use a custom validation strategy
          1. Using alternative configuration add-ons
        3. Testing the custom validation strategy
        4. Extending ExtVal in many other ways
      7. Extending ExtVal with add-ons
        1. Getting add-ons for ExtVal
        2. Installing ExtVal add-ons
      8. Using Bean Validation
        1. Setting up Bean Validation and ExtVal
        2. Using Bean Validation annotations
        3. Reusing validation
          1. Inheriting validation
          2. Using recursive validation
          3. Composing custom constraints
        4. Using payloads to set severity levels
          1. Setting up the Continue with warnings add-on
          2. Setting the severity level of a constraint
          3. Setting the severity level on ExtVal Property Validation constraints
          4. Setting the severity level on any constraint
      9. Summary
    17. 11. Best Practices
      1. Preventing direct access to page definitions
      2. Using container-managed security with JSF
        1. Enabling container-managed security
        2. Navigating to the login page
        3. Creating the login page
          1. Alternatives
        4. Logout link
      3. Component bindings
      4. Keeping the state of a component
      5. Summary