Movatterモバイル変換


[0]ホーム

URL:


Document Information

Preface

Part I Introduction

1.  Overview

2.  Using the Tutorial Examples

Part II The Web Tier

3.  Getting Started with Web Applications

4.  Java Servlet Technology

5.  JavaServer Pages Technology

6.  JavaServer Pages Documents

7.  JavaServer Pages Standard Tag Library

8.  Custom Tags in JSP Pages

9.  Scripting in JSP Pages

10.  JavaServer Faces Technology

11.  Using JavaServer Faces Technology in JSP Pages

The Example JavaServer Faces Application

Setting Up a Page

Using the Core Tags

Adding UI Components to a Page Using the HTML Component Tags

UI Component Tag Attributes

Theid Attribute

Theimmediate Attribute

Therendered Attribute

Thestyle andstyleClass Attributes

Thevalue andbinding Attributes

Adding a Form Component

Using Text Components

Rendering a Text Field with theinputText Tag

Rendering a Label with theoutputLabel Tag

Rendering a Hyperlink with theoutputLink Tag

Displaying a Formatted Message with theoutputFormat Tag

Rendering a Password Field with theinputSecret Tag

Using Command Components for Performing Actions and Navigation

Rendering a Button with thecommandButton Tag

Rendering a Hyperlink with thecommandLink Tag

Using Data-Bound Table Components

Adding Graphics and Images with thegraphicImage Tag

Laying Out Components with theUIPanel Component

Rendering Components for Selecting One Value

Displaying a Check Box Using theselectBooleanCheckbox Tag

Displaying a Menu Using theselectOneMenu Tag

Rendering Components for Selecting Multiple Values

TheUISelectItem,UISelectItems, andUISelectItemGroup Components

Using theselectItems Tag

Using theselectItem Tag

Displaying Error Messages with themessage andmessages Tags

Using Localized Data

Loading a Resource Bundle

Referencing Localized Static Data

Referencing Error Messages

Using the Standard Converters

Converting a Component's Value

UsingDateTimeConverter

UsingNumberConverter

Registering Listeners on Components

Registering a Value-Change Listener on a Component

Registering an Action Listener on a Component

Using the Standard Validators

Validating a Component's Value

Using theLongRangeValidator

Binding Component Values and Instances to External Data Sources

Binding a Component Value to a Property

Binding a Component Value to an Implicit Object

Binding a Component Instance to a Bean Property

Binding Converters, Listeners, and Validators to Backing Bean Properties

Referencing a Backing Bean Method

Referencing a Method That Performs Navigation

Referencing a Method That Handles an Action Event

Referencing a Method That Performs Validation

Referencing a Method That Handles a Value-change Event

Using Custom Objects

Using a Custom Converter

Using a Custom Validator

Using a Custom Component

12.  Developing with JavaServer Faces Technology

13.  Creating Custom UI Components

14.  Configuring JavaServer Faces Applications

15.  Internationalizing and Localizing Web Applications

Part III Web Services

16.  Building Web Services with JAX-WS

17.  Binding between XML Schema and Java Classes

18.  Streaming API for XML

19.  SOAP with Attachments API for Java

Part IV Enterprise Beans

20.  Enterprise Beans

21.  Getting Started with Enterprise Beans

22.  Session Bean Examples

23.  A Message-Driven Bean Example

Part V Persistence

24.  Introduction to the Java Persistence API

25.  Persistence in the Web Tier

26.  Persistence in the EJB Tier

27.  The Java Persistence Query Language

Part VI Services

28.  Introduction to Security in the Java EE Platform

29.  Securing Java EE Applications

30.  Securing Web Applications

31.  The Java Message Service API

32.  Java EE Examples Using the JMS API

33.  Transactions

34.  Resource Connections

35.  Connector Architecture

Part VII Case Studies

36.  The Coffee Break Application

37.  The Duke's Bank Application

Part VIII Appendixes

A.  Java Encoding Schemes

B.  About the Authors

Index

 

The Java EE 5 Tutorial

Java Coffee Cup logo
PreviousContentsNext

Setting Up a Page

A typical JavaServer Faces page includes the following elements:

  • A set of tag library declarations that declare the two JavaServer Faces tag libraries

  • Aview tag

  • Aform tag

This section tells you how to add these elements to your pagesand briefly describes thesubview tag for including JavaServer Faces pages inside other pages.

To use the JavaServer Faces UI components in your JSP page, you needto give the page access to the two standard tag libraries: theJavaServer Faces HTML render kit tag library and the JavaServer Faces core taglibrary. The JavaServer Faces standard HTML render kit tag library defines tags that representcommon HTML user interface components. The JavaServer Faces core tag library defines tagsthat perform core actions and are independent of a particular render kit.

Using these tag libraries is similar to using any other custom taglibrary. This chapter assumes that you are familiar with the basics of usingcustom tags in JSP pages (seeUsing Custom Tags).

As is the case with any tag library, each JavaServer Faces tag librarymust have a TLD that describes it. Thehtml_basic TLD describes the JavaServerFaces standard HTML render kit tag library. Thejsf_core TLD describes theJavaServer Faces core tag library.

Refer to theTLD documentation athttp://download.oracle.com/javaee/5/javaserverfaces/1.2/docs/tlddocs/ for a complete list of theJavaServer Faces tags and their attributes.

To use any of the JavaServer Faces tags, you need to include thesetaglib directives at the top of each page containing the tags defined bythese tag libraries:

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %><%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

Theuri attribute value uniquely identifies the TLD. Theprefix attribute value isused to distinguish tags belonging to the tag library. You can use otherprefixes rather than theh orf prefixes. However, you must usethe prefix you have chosen when including the tag in the page. Forexample, theform tag must be referenced in the page using theh prefix because the preceding tag library directive uses theh prefix to distinguishthe tags defined inhtml_basic.tld:

<h:form ...>

A page containing JavaServer Faces tags is represented by a tree of components.At the root of the tree is theUIViewRoot component. Theview tagrepresents this component on the page. Therefore, all component tags on the pagemust be enclosed in theview tag, which is defined in thejsf_coreTLD:

<f:view>    ... other JavaServer Faces tags, possibly mixed with other     content ...</f:view>

You can enclose other content, including HTML and other JSP tags, within theview tag, but all JavaServer Faces tags must be enclosed within theviewtag.

Theview tag has four optional attributes:

  • Alocale attribute. If this attribute is present, its value overrides theLocale stored in theUIViewRoot component. This value is specified as aString and must be of this form:

    :language:[{-,_}:country:[{-,_}:variant]

    Thelanguage,country, andvariant parts of the expression are as specified injava.util.Locale.

  • ArenderKitId attribute. A page author uses this attribute to refer to the ID of the render kit used to render the page, therefore allowing the use of custom render kits. If this attribute is not specified, the default HTML render kit is assumed. The process of creating custom render kits is outside the scope of this tutorial.

  • AbeforePhase attribute. This attribute references a method that takes aPhaseEvent object and returnsvoid, causing the referenced method to be called before each phase (except restore view) of the life cycle begins.

  • AnafterPhase attribute. This attribute references a method that takes aPhaseEvent object and returns void, causing the referenced method to be called after each phase (except restore view) in the life cycle ends.

An advanced developer might implement the methods referenced bybeforePhase andafterPhaseto perform such functions as initialize or release resources on a per-page basis.This feature is outside of the scope of this tutorial.

Theform tag is nested inside of theview tag. As its namesuggests, theform tag represents a form, which is submitted when a buttonor hyperlink on the page is clicked. For the data of other componentson the page to be submitted with the form, the tags representing thecomponents must be nested inside theform tag. SeeAdding a Form Component for moredetails on using theform tag.

If you want to include a page containing JavaServer Faces tags within anotherJSP page that includes JavaServer Faces tags, you must enclose the entire nestedpage in asubview tag. You can add thesubview tag on theparent page and nest ajsp:include inside it to include the page:

<f:subview>    <jsp:include page="theNestedPage.jsp" /></f:subview>

You can also include thesubview tag inside the nested page, but itmust enclose all the JavaServer Faces tags on the nested page.

Thesubview tag has two optional attributes:binding andrendered. Thebindingattribute binds to a component that implementsNamingContainer. One potential use case of bindinga subview component to a bean is if you want to dynamically addcomponents to the subview in the backing bean.

Therendered attribute can be set totrue orfalse, indicating whetheror not the components nested in thesubview tag should be rendered.

In summary, a typical JSP page that uses JavaServer Faces tags will looksomewhat like this:

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %><%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %><f:view>    <h:form>        other JavaServer Faces tags and core tags,         including one or more button or hyperlink components for         submitting the form    </h:form></f:view>

The sectionsUsing the Core Tags andAdding UI Components to a Page Using the HTML Component Tags describe how to use the core tagsfrom the JavaServer Faces core tag library and the component tags from theJavaServer Faces standard HTML render kit tag library.

PreviousContentsNext

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.Legal Notices


[8]ページ先頭

©2009-2025 Movatter.jp