Table 4.2 Child Elements CHILD ELEMENT MULTIPLICITY DESCRIPTIONapplication zero to many You may optionally replace the default action listener, navigation handler, property resolver, an
Trang 1<managed-bean-name> customer </managed-bean-name>
<managed-bean-class> carstore.CustomerBean </managed-bean-class>
<managed-bean-scope> session </managed-bean-scope>
<managed-bean-name> carstore </managed-bean-name>
<managed-bean-class> carstore.CarStore </managed-bean-class>
<managed-bean-scope> session </managed-bean-scope>
Trang 3this file later when we discuss declaring UI components and Renderers
<!DOCTYPE faces-config PUBLIC
“-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN”
Trang 7The <faces-config> Element
This element is the root of every faces configuration file and contains all figuration settings for a JSF application other than those defined in the Webapplication descriptor A summary of each possible child element is provided
con-in Table 4.2
Trang 8Table 4.2 <faces-config> Child Elements CHILD ELEMENT MULTIPLICITY DESCRIPTION
application zero to many You may optionally replace the default
action listener, navigation handler, property resolver, and variable resolver for your application.
factory zero to many Provides factory implementations of
things like faces context, life cycle, render kit, and application resources component zero to many Custom UI components (other than
standard JSF components).
converter zero to many Converters for encoding and decoding
UI component values.
managed-bean zero to many Objects that are automatically created,
initialized, and placed into proper scope when invoked by a UI component.
navigation-rule zero to many Navigation rules that are used in the
decision flow of your application.
referenced-bean zero to many Bean references that are expected to
be in scope where used in your user interface code.
render-kit zero to many RenderKits for rendering UI
components in your application.
lifecycle zero to many Provides modifications to the default
life cycle.
validator zero to many Validators for ensuring the correctness
of data entered by users in application
UI components.
We’ll cover each of these elements, along with their child elements, in thefollowing sections
The <application> Element
This element allows you to replace the default action handler, navigationhandler, and resolvers for properties and variables Replacing the defaults pro-vided with your JSF implementation is unnecessary for most applications butmay be done if one or more of them are inadequate A summary of each possi-ble child element is provided in Table 4.3
Trang 9Table 4.3 <application> Child Elements CHILD ELEMENT MULTIPLICITY DESCRIPTION
action-listener zero to many The fully qualified class name of the
concrete ActionListener implementation class that processes action events emitted from UI components.
message-bundle zero to many Base name (and optionally package
when appropriate) of a resource bundle that contains message resources for the application (see the JavaDocs for java.util.ResourceBundle for more information).
navigation-handler zero to many The fully qualified class name of
the concrete NavigationHandler implementation class that determines next steps in application flow.
view-handler zero to many The fully qualified class name of the
concrete ViewHandler implementation class that is called by
the Restore View and Render Responsephases of the request processing life cycle.
property-resolver zero to many The fully qualified class name of the
concrete PropertyResolver implementation class that resolves all property references in your
application.
variable-resolver zero to many The fully qualified class name
of the concrete VariableResolver implementation class that resolves all variable references in your application.
local-config zero to many Provides supported locales
supported by the application (including an optional default).
The Car Demo application, like typical JSF applications, does not replacethese default resources provided by the JSF implementation
The <factory> Element
This element allows you to declaratively provide factory implementations ofthings like the faces context, life cycle, render kits, and application resources
A summary of each possible child element is provided in Table 4.4
Trang 10Table 4.4 <factory> Child Elements CHILD ELEMENT MULTIPLICITY DESCRIPTION
application-factory zero to many The fully qualified class name of the
ApplicationFactory implementation class (its instances provide a host of basic resources and behavior needed by JSF applications) that should replace the default provided by your JSF
implementation.
faces-context-factory zero to many The fully qualified class name of the
FacesContextFactory implementation class (which provides FacesContext instances) that should replace the default provided by your JSF implementation.
lifecycle-factory zero to many The fully qualified class name of the
LifecycleFactory implementation class (the Lifecycle instances it provides manage the entire JSF request- processing life cycle) that should replace the default provided by your JSF
implementation.
render-kit-factory zero to many The fully qualified class name of the
RenderKitFactory implementation class (provides access to available render kits) that should replace the default provided
by your JSF implementation.
This element allows you to add custom extensions to your JSF tion Most JSF developers won’t use this mechanism, but it is very useful whenadjustments to a particular JSF implementation are necessary
implementa-The <message-bundle> and <local-config> Elements
The <message-bundle> element represents a bundle of localized messages,while the <local-config> element defines all supported locales (including
an optional default) You can use these elements to support tion in your application Listing 4.2 provides a good example of these elements
Trang 11Each other supported locale is specified via a <supported-locale> tag
The <attribute> Element
This element provides a method for declaratively defining generic attributesfor UI components, Converters, Renderers, and Validators Each attribute isavailable to the programming logic of the parent component as well as othercomponents (including event handlers) that manipulate it A summary of eachpossible child element is provided in Table 4.5
Table 4.5 <attribute> Child Elements CHILD ELEMENT MULTIPLICITY DESCRIPTION
description zero to many A textual description of the generic
attribute.
display-name zero to many A short, descriptive name of the generic
attribute for representing the generic attribute in JSF tools.
icon zero to many Small and large icons for representing
the generic attribute that are intended for JSF tools.
attribute-name exactly one The name under which the generic
attribute is stored in its parent (UI components, Converters, and so on) and its value is keyed on.
attribute-class exactly one Defines the Java type for the generic
attribute (java.lang.String, and so forth).
suggested-value zero or one Provides a value for the attribute that is
used for tools when populating palettes.
attribute-extension zero to many Provides a place for content specific to a
particular JSF implementation.
Trang 12You’ll notice that the FormatValidator in Listing 4.2 provides a Patterns attribute for specifying format patterns that a particular value(from a UIInput component) will be validated against.
<h:message styleClass=”validationMessage” for=”zip”/>
You can see here how the formatPatterns attribute is set inside the JSP
To see how the attribute is accessed and used, take a look at the idatorand FormatValidatorTag classes
FormatVal-The <property> Element
This element provides a method for declaratively defining standard JavaBeanproperties for UI components, Converters, and Validators You will typicallyuse this element to make properties available for tool manipulation A sum-mary of each possible child element is provided in Table 4.6
Table 4.6 <property> Child Elements CHILD ELEMENT MULTIPLICITY DESCRIPTION
description zero to many A textual description of the property display-name zero to many A short, descriptive name of the
property for display in JSF tools.
Icon zero to many Small and large icons for representing
the property in JSF tools.
property-name exactly one The name of the property (following
standard JavaBean naming conventions).
Trang 13Table 4.6 (continued)
CHILD ELEMENT MULTIPLICITY DESCRIPTION
property-class exactly one Defines the Java type for the property
(java.lang.String, for example).
suggested-value zero or one Provides a value for the property that is
used for tools when populating palettes.
property-extension zero to many Provides a place for content specific to a
particular JSF implementation.
The <component> Element
This element allows you to declare a new UI component for your application
or replace an existing one, while registering it under a unique identifier Alongwith each component, you will also declare the component’s available attrib-utes and properties Each UI component you use in your application, otherthan the standard components provided with JSF, will be declared using thiselement A summary of each possible child element is provided in Table 4.7
Table 4.7 <component> Child Elements CHILD ELEMENT MULTIPLICITY DESCRIPTION
description zero to many A textual description of the UI
component.
display-name zero to many A short, descriptive name of the UI
component for display in JSF tools.
icon zero to many Small and large icons for representing
the UI component in JSF tools.
component-type exactly one Represents the name under which the
UI component will be registered; this name must be unique within your application.
component-class exactly one Defines the fully qualified type of the UI
component, which must be an implementation of UI component.
attribute zero to many Defines a generic attribute for the UI
component.
property zero to many Defines a generic JavaBean property on
the UI component.
component- zero or more Provides a place for content specific to a
Trang 14There are a number of custom UI components defined in Listing 4.3, one ofwhich is repeated here.
</description>
Trang 15</attribute>
Trang 16To see an example of how this component is used in a JSP, check out thechooseLocale.jsppage in the Car Demo application The following codeshows the tag library being declared and the DemoArea component beingused.
<%@ taglib uri=”http://java.sun.com/jsf/demo/components” prefix=”d” %>
<d:area id=”NAmerica” value=”#{NA}”
The <converter> Element
This element allows you to declare each of the custom Converters that are used
in your application As with UI components, you will also declare the verter’s available attributes and properties A summary of each possible childelement is provided in Table 4.8
Con-Table 4.8 <converter> Child Elements CHILD ELEMENT MULTIPLICITY DESCRIPTION
description zero to many A textual description of the Converter display-name zero to many A short, descriptive name of the
Converter for display in JSF tools.
icon zero to many Small and large icons for representing
the Converter in JSF tools.
converter-id exactly one Represents the identifier under which
the Converter will be registered; this identifier must be unique within your application.
converter-class exactly one Defines the fully qualified type of the
Converter, which must be an implementation of Converter.
attribute zero to many Defines a generic attribute for the
Converter.
property zero to many Defines a generic JavaBean property on
the Converter.
Trang 17The CreditCardConverter in Listing 4.2 is registered in the Car Demoapplication with an identifier of creditcard.
<h:message styleClass=”validationMessage” for=”ccno”/>
See Chapter 8, “Validation and Conversion,” for more information aboutcreating and configuring Converter components
The <managed-bean> Element
This element declares UI component model objects represented by JavaBeansand can be used to dynamically instantiate and initialize them when firstinvoked by UI components A summary of each possible child element is pro-vided in Table 4.9
Table 4.9 <managed-bean> Child Elements CHILD ELEMENT MULTIPLICITY DESCRIPTION
description zero to many A textual description of the managed
bean.
display-name zero to many A short, descriptive name of the
managed bean for display in JSF tools.
icon zero to many Small and large icons for representing
the managed bean in JSF tools.
(continued)
Trang 18Table 4.9 (continued)
CHILD ELEMENT MULTIPLICITY DESCRIPTION
managed-bean- exactly one Represents the attribute name under
stored (if the scope is something other than “none”); this name must be unique within your application.
managed-bean- exactly one Defines the fully qualified type of the
and that will be used to create instances when invoked.
managed-bean- exactly one Specifies the scope of the managed
“session,” “application,” or “none.”
A value of “none” results in the managed bean’s not being persisted between requests.
managed-property zero to many Defines an individual property of the
managed bean.
You will most likely use this element to configure and initialize UI nent model objects Listing 4.2 provides an example of this element in use forthe Car Demo application
<managed-bean-name> customer </managed-bean-name>
<managed-bean-class> carstore.CustomerBean </managed-bean-class>
<managed-bean-scope> session </managed-bean-scope>
</managed-bean>
Here, we are defining the Customer object that will support the input formpresented in the Customer.jsp page An identifier (or name) is providedalong with the backing JavaBean class that the JSF implementation must create
an object from when necessary We have also specified that the Customerobject be placed in session scope when created
Trang 19Table 4.10 <managed-property> Child Elements CHILD ELEMENT MULTIPLICITY DESCRIPTION
description zero to many A textual description of the managed
property.
display-name zero to many A short, descriptive name of the
managed property for display in JSF tools.
icon zero to many Small and large icons for representing
the managed property in JSF tools.
property-name exactly one Represents the corresponding JavaBean
property on the parent managed bean.
property-class zero or one Defines the fully qualified type of the
(optional) class that represents the managed
property; this class should be specified if the configuration file will be used to generate the managed bean and its properties.
map-entries, exactly one A managed property may be initialized null-value, value, as a Map (map-entries), a List or array list-entries (list-entries), a value of null (null-value),
or a literal value (value).
The <managed-property> Element
This element represents a property of a managed bean and allows you todeclaratively define initialization parameters that will be set when the parentmanaged bean is automatically initialized by the JSF implementation you areusing A summary of each possible child element is provided in Table 4.10
You will typically want to declare each property on a managed bean thatyou wish to initialize before use The North American image map from thechooseLocale.jspJSP page provides a good example of this
<managed-bean>
<description>
Causes the default VariableResolver implementation to instantiate the managed bean, NA of the class, components.model.ImageArea in application scope if the bean does not already exist in any scope and initialize the shape, alt, and coords properties with the values specified by the managed-property elements
</description>
Trang 20<managed-bean-name> NA </managed-bean-name>
<managed-bean-class> components.model.ImageArea </managed-bean-class>
<managed-bean-scope> application </managed-bean-scope>
The <map-entries> Element
For a managed property of type java.util.Map, this element allows you toinitialize it with a set of key value pairs A summary of each possible child ele-ment is provided in Table 4.11
Trang 21Table 4.11 <map-entries> Child Elements CHILD ELEMENT MULTIPLICITY DESCRIPTION
key-class zero or one Defines the fully qualified class name to
(optional) which each “key” element in a set of
“map-entry” elements will be converted to; if omitted, java.lang.String is assumed.
value-class zero or one Defines the fully qualified class name to
(optional) which each “value” element will be
converted to, prior to adding it to the
“values” list for a managed property that
is a Collection or Array; if omitted, java.lang.String is assumed.
map-entry zero or more A key-value pair that will be used to
initialize a managed property of type java.util.Map.
In addition to initializing a property to a single value or object, you may alsoinitialize a property to a map of values For example, we could choose to rep-resent options and their prices for the SUV in a map
Trang 22spec-Table 4.12 <map-entry> Child Elements CHILD ELEMENT MULTIPLICITY DESCRIPTION
key exactly one Provides the String representation of the
key.
null-value or value exactly one Provides the value associated with the
key as a value of null (null-value) or a literal value.
keys if a key class is specified) can be converted to the specified class See the
JavaServer Pages 2.0 Specification for more information on conversion rules.
The <map-entry> Element
This element represents a single key-value pair that will be used to initialize itsparent managed property of type java.util.Map We looked at an example
of this in the previous section A summary of each possible child element isprovided in Table 4.12
The <list-entries> Element
This element represents a number of elements that will be used to initialize amanaged property that is either a List or an array A summary of each possiblechild element is provided in Table 4.13
Similarly to the <map-entries> element, you may use the <values> ment to define a compound property made up of a List or an array For exam-ple, we could choose to represent all of the state codes in a collection
ele-Table 4.13 <list-entries> Child Elements CHILD ELEMENT MULTIPLICITY DESCRIPTION
value-class zero or one For a managed property of type List, you
(optional) may optionally specify a fully qualified
type that each element will be converted
to before being added to the List This is very useful for Lists that require all elements to have the same type.
null-value or value zero or more This provides the value, which may be
either null (null-value) or a literal value
Trang 23The <navigation-rule> Element
This element defines one decision point in the flow of your application’s userinterface The navigation rule elements you define will be used by the defaultNavigationHandlerof your JSF implementation (or the one you optionallyreplace it with using the application element) to determine next steps in yourworkflow A summary of each possible child element is provided in Table 4.14
Table 4.14 <navigation-rule> Child Elements CHILD ELEMENT MULTIPLICITY DESCRIPTION
description zero to many A textual description of the navigation
rule.
display-name zero to many A short, descriptive name of the
navigation rule for display in JSF tools.
icon zero to many Small and large icons for representing
the navigation rule in JSF tools.
from-view-id zero or one Defines the component tree identifier
(optional) for which the navigation rule applies; if
no identifier is supplied, then the navigation rule will apply to all component trees.
navigation-case zero to many Defines one possible outcome for the
navigation rule.
Trang 24The <navigation-rule> element is used to define either an outcome thatapplies to all pages in the application or one that applies specifically whencoming from a particular page The code in Listing 4.2 provides the applicationflow for Car Demo, a piece of which is repeated here.