background image

The setProperties Method

<< Performing Decoding | Saving and Restoring State >>
<< Performing Decoding | Saving and Restoring State >>

The setProperties Method

"Creating the Component Tag Handler" on page 430
describes how MapTag, the tag handler for
the map tag, sets the component's values when processing the tag. It does this by providing the
following:
A method for each attribute that takes either a ValueExpression or MethodExpression
object depending on what kind of expression the attribute accepts.
A setProperties method that stores the ValueExpression or MethodExpression object
for each component property so that the component class can retrieve the expression object
later.
To retrieve the expression objects that setProperties stored, the component class must
implement a method for each property that accesses the appropriate expression object, extracts
the value from it and returns the value.
Because MapComponent extends UICommand, the UICommand class already does the work of
getting the ValueExpression and MethodExpression instances associated with each of the
attributes that it supports.
However, if you have a custom component class that extends UIComponentBase, you will need
to implement the methods that get the ValueExpression and MethodExpression instances
associated with those attributes that are enabled to accept expressions. For example, if
MapComponent
extended UIComponentBase instead of UICommand, it would need to include a
method that gets the ValueExpression instance for the immediate attribute:
public boolean isImmediate() {
if (this.immediateSet) {
return (this.immediate);
}
ValueExpression ve = getValueExpression(
"immediate");
if (ve != null) {
Boolean value = (Boolean) ve.getValue(
getFacesContext().getELContext());
return (value.booleanValue());
} else {
return (this.immediate);
}
}
The properties corresponding to the component attributes that accept method expressions
must accept and return a MethodExpression object. For example, if MapComponent extended
UIComponentBase
instead of UICommand, it would need to provide an action property that
returns and accepts a MethodExpression object:
public MethodExpression getAction() {
return (this.action);
}
public void setAction(MethodExpression action) {
Creating Custom Component Classes
Chapter 13 · Creating Custom UI Components
425