background image

Setting Method Expressions

<< Setting Component Property Values | Releasing Resources >>
<< Setting Component Property Values | Releasing Resources >>

Setting Method Expressions

Boolean(immediate.getExpressionString()).
booleanValue());
}
}
Setting Method Expressions on Component Properties
The process of setting the properties that accept method expressions is done differently
depending on the purpose of the method. The actionListener attribute uses a method
expression to reference a method that handles action events. The action attribute uses a
method expression to either specify a logical outcome or to reference a method that returns a
logical outcome, which is used for navigation purposes.
To handle the method expression referenced by actionListener, the setProperties method
must wrap the expression in a special action listener object called
MethodExpressionActionListener
. This listener executes the method referenced by the
expression when it receives the action event. The setProperties method then adds this
MethodExpressionActionListener
object to the list of listeners to be notified when the event
of a user clicking on the map occurs. The following piece of setProperties does all of this:
if (actionListener != null) {
map.addActionListener(
new MethodExpressionActionListener(actionListener));
}
If your component fires value change events, your tag handler's setProperties method does a
similar thing, except it wraps the expression in a MethodExpressionValueChangeListener
object and adds the listener using the addValueChangeListener method.
In the case of the method expression referenced by the action attribute, the setProperties
method uses the setActionExpression method of ActionSource2 to set the corresponding
property on MapComponent:
if (action != null) {
map.setActionExpression(action);
}
Providing the Renderer Type
After setting the component properties, the tag handler provides a renderer type (if there is a
renderer associated with the component) to the JavaServer Faces implementation. It does this
using the getRendererType method:
public String getRendererType() {return
"DemoMap";}
The renderer type that is returned is the name under which the renderer is registered with the
application. See
"Delegating Rendering to a Renderer" on page 427
for more information.
Creating the Component Tag Handler
Chapter 13 · Creating Custom UI Components
433