GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||
GeezerVison is showing javaee.github.io — Managed Beans in JavaServer Faces Technology
Managed Beans in JavaServer Faces TechnologyA typical JavaServer Faces application includes one or more managed beans, each of which can be associated with the components used in a particular page. This section introduces the basic concepts of creating, configuring, and using managed beans in an application.
The following topics are addressed here: Creating a Managed BeanA managed bean is created with a constructor with no arguments, a set of properties, and a set of methods that perform functions for a component. Each of the managed bean properties can be bound to one of the following:
The most common functions that managed bean methods perform include the following:
As with all JavaBeans components, a property consists of a private data field and a set of accessor methods, as shown by this code:
When bound to a component’s value, a bean property can be any of the
basic primitive and numeric types or any Java object type for which the
application has access to an appropriate converter. For example, a
property can be of type When a bean property is bound to a component instance, the property’s
type must be the same as the component object. For example, if a
For more information on writing beans and their properties, see Writing Bean Properties. Using the EL to Reference Managed BeansTo bind component values and objects to managed bean properties or to reference managed bean methods from component tags, page authors use the Expression Language syntax. As explained in Overview of the EL, the following are some of the features that the EL offers:
Deferred evaluation of expressions is important because the JavaServer
Faces lifecycle is split into several phases in which component event
handling, data conversion and validation, and data propagation to
external objects are all performed in an orderly fashion. The
implementation must be able to delay the evaluation of expressions until
the proper phase of the lifecycle has been reached. Therefore, the
implementation’s tag attributes always use deferred-evaluation syntax,
which is distinguished by the To store data in external objects, almost all JavaServer Faces tag attributes use lvalue expressions, which are expressions that allow both getting and setting data on external objects. Finally, some component tag attributes accept method expressions that reference methods that handle component events or validate or convert component data. To illustrate a JavaServer Faces tag using the EL, the following tag references a method that validates user input:
This tag binds the Nearly all JavaServer Faces tag attributes accept value expressions. In addition to referencing bean properties, value expressions can reference lists, maps, arrays, implicit objects, and resource bundles. Another use of value expressions is to bind a component instance to a
managed bean property. A page author does this by referencing the
property from the
In addition to using expressions with the standard component tags, you
can configure your custom component properties to accept expressions by
creating For information on the EL, see Chapter 9, "Expression Language". For information on referencing managed bean methods from component tags, see Referencing a Managed Bean Method.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
| ||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |