|
Basic JSF Features

|
|
Record all objects that are exposed to the view. This involves their name or handle, as used across the view tier, and the class they represent.
For JSF, the objects exposed to the view are defined in faces-config.xml file. Some of these fall into the following groups.
- managed-bean
- message-bundle
- validator
- converter
Irrespective of the kind of object, the most important information are the define-id and define-class, the rest of the attributes when applicable; the session attribute has default.
BEHAVIOR DESCRIPTORS |
id |
type |
data-source |
value |
define-id |
define-class |
define-scope |
details |
| customerOrderBean |
define |
|
|
customerOrderBean |
com.example.CustomerOrder. |
session |
|
Despite the categories of objects that could be exposed to the view, as listed above, there is nothing specific that distinguishes their entries explicitly within the behavior descriptor. However, they would differ in nature, in the way that could not be mistaken.
| managed-bean | The "managed-bean" element represents a JavaBean. Unlike some other platform, there is no required interface or base class. Although any interface could be in use, it is inconceivable that any of those listed below, in this column, would be relevant. |
| validator | Must subscribe to interface javax.faces.validator.Validator |
| converter | Must subscribe to interface javax.faces.validator.Converter |
Although, as shown above, these groups of classes are distinguishable, it is common practice to use naming convention that distinguishes them. For instance, validators could always have the type included in the names, like FormatValidator.
Managed Bean
The information needed for this declaration is easy to map from the descriptor, as shown below.
For the declarative backing bean definition, the following attributes are employed.
| Attribute | Example | config. entry |
| id | Any unique identifier used purely for referencing the definition on the page. |
| define-id | customerOrderBean | <managed-bean-name> |
| define-class | com.example.CustomerOrder | <managed-bean-class> |
| define-scope | session | <managed-bean-scope> |
| details | description | <managed-bean-description> |
The corresponding entry in the JSF configuration file would be as follows:
<managed-bean>
<managed-bean-name>customerOrderBean</managed-bean-name>
<managed-bean-class>com.example.CustomerOrder</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
Resource Bundle
Another object exposed to the view is the resource bundle, used for displaying messages that could be internationalized. On the JSF, these are indistinguishable from regular objects, since the same object.property (bundle.key) is used to retrieve their contents. This actually restricts the naming convention that could be used for the key. Inclusion of additional period would be misunderstood; as the normal use is for nested objects.
| id | Any unique identifier used as the definition reference on the page |
| define-id | bundle | var |
| define-class | LocalizationResource | basename |
| define-scope | | N/A |
| detail | | Resource Bundle |
The implementation entry is on the view page; which makes sense since it only related to the page. Example is shown below.
<f:loadbundle basename="LocalizationResource" var="bundle"/>
Validator
| id | Any unique identifier used as the definition reference on the page |
| define-id | FormatValidator | <validator-id> |
| define-class | com.example.FormatValidator | <validator-class> |
| define-scope | | N/A |
| details | description | <managed-bean-description> |
The corresponding entry in the JSF configuration file would be as follows:
<validator>
<validator-id>FormatValidator</validator-id>
<validator-class>com.example.FormatValidator</validator-class>
</validator>
Converter
| id | Any unique identifier used as the definition reference on the page |
| define-id | creditCardConverter | <converter-id> |
| define-class | com.example.CreditCardConverter | <converter-class> |
| define-scope | | N/A |
| details | description | <managed-bean-description> |
The corresponding entry in the JSF configuration file would be as follows:
<converter>
<converter-id>creditCardConverter</Converter-id>
<converter-class>com.example.CreditCardConverter</Converter-class>
</converter>
More details are available in the attributes descriptions
type
id
data-source
value
define-id
define-class
define-scope
|
SEAM Enhancements
Managed Bean
It is the same declarations allowed in the faces-config.xml tat Seam provides facilities for with annotations.
For managed beans, the mappings to dWebSpec behavior attributes to the annotations are shown below..
| Attribute
| Implementation Annotation |
| id |
|
| define-id |
@name("customerOrderBean") |
| define-class |
Class name |
| define-scope |
@scope("session") |
| details |
|
| data-source |
|
Example of such specification is shown below.
BEHAVIOR DESCRIPTORS |
id |
type |
data-source |
value |
define-id |
define-class |
define-scope |
details |
| customerOrderBean |
define |
|
|
customerOrderBean |
com.example.CustomerOrder.
|
session |
|
The corresponding entry using Seam annotations would be as follows:
package com.example;
@scope("session")
@name("customerOrderBean")
class CustomerOrder {
Dependent ObjectsThe annotations described above are for the "managed components". These result in objects with framework managed life-cycle that are exposed to the view tier within contexts.
There is another mechanism for exposing objects to the view tier, using "outjection". With this, the parent object is in charge of the initial creation of the object; thereafter these objects have their own independent exposure within contexts. These are dependent object, since they depend on a component for the start of their life-cycle.
NOTE: There is also the mechanism of injection, as popularized by the Spring Framework; this assist in injecting dependencies to the components in a scheme that is not necessarily exposed to the view tier, as such not subjects for the behaviors.
For dWebSpec specification, an object is dependent, if in it definition it has data-source. The data-source would have influence on its life cycle. The implementation transformation for dependent objects is shown below.
Example of such specification is shown below.
BEHAVIOR DESCRIPTORS |
id |
type |
data-source |
value |
define-id |
define-class |
define-scope |
details |
| orderTypes |
define |
customerOrderBean |
|
orderTypes |
com.example.OrderTypes |
session |
|
The annotation for this specification would show up in the parent class as shown below.
@out("session") OrderTypes orderTypes
NOTE: There is a choice between applying the annotation to the field or to its getter method.
Managed Beans Types
We have shown the declaration of managed beans; however there are different categories of such objects. These are mainly
| EJB Stateful Session Bean |
| Entity Bean |
| EJB Stateless Session Bean |
| EJB Message Driven Bean |
| JavaBean (POJO) |
The designations of these categories are not part of dWebSpec specification, which only capture the common denominators which is the class and object. Although the details attribute could be used to specify the categories, it should be noted that the aim of the behavior descriptor is integration. The true specification of the managed component would reside in the model specifications.
Validator
The specification of the validator classes is almost non-distinguishable from those for other objects. The point is that they are only applicable for validations and subscribe to specific interface.
| id |
Any unique identifier used as the definition reference on the page
|
| define-id
|
formatValidator
|
@name("formatValidator")
|
| define-class
|
com.example.FormatValidator
|
FormatValidator
|
| define-scope
|
|
N/A
|
| details
|
|
description
|
The corresponding annotations are shown below:
package com.example;
@Name("formatValidator")
@BypassInterceptors
@Converter
class FormatValidator {
Converter
The specification of the converters classes is almost non-distinguishable from those for other objects. The point is that they are only applicable for conversion and subscribe to specific interface
| id |
Any unique identifier used as the definition reference on the page |
| define-id |
creditCardConverter |
@name(“creditCardConverter”) |
| define-class |
com.example.CreditCardConverter |
CreditCardConverter |
| define-scope |
|
N/A |
| details |
|
description |
The corresponding annotations are shown below:
package com.example;
@Name("creditCardConverter")
@BypassInterceptors
@Converter
class CreditCardConverter {
|