By: Daniel Malcolm Emailed: 1728 times Printed: 2329 times
While using Action Listener, a value is attached to a change listener
or an action listener to a
JSF element by using the valueChangeListener or actionListener attributes. When using the attribute syntax, you use a method-binding expression to bind a method as a listener. However, this works only when attaching a single listener.
When you need to attach multiple listeners, there is a JSF tag for value change listeners and one for action listeners that can be used to attach one or more listeners to an element. When using the tag syntax, you will be specifying a class that implements a listener interface. For value change listeners, the tag is <f:valueChangeListener>, with an attribute named type that is the class name of the listener. The interface that the listener must implement is javax.faces.event.ValueChangeListener. It has a single method that must be implemented:
So, if we assume that the FlightSearch and FlightTypes classes both implement ValueChangeListener, we could attach both of them to an element like this:
For action listeners, the tag is <f:actionListener>, with an attribute named type that is the class name of the listener. The interface that the listener must implement is javax.faces.event.ActionListener. It has a single method that must be implemented:
If we assume that the FlightSearch and FlightTypes classes both implement ActionListener, we could attach both of them to an element, like this:
In either of the two preceding examples, both listeners will be called at the appropriate time to respond to the event. If any listeners are attached by using attribute syntax, they will be called first. Then any listeners attached by using tag syntax will be called, in order of declaration.
View Tutorial By: Robert Willems at 2011-11-29 06:26:21
Most Viewed Articles (in JSF )
Most Emailed Articles (in JSF)