The @ListenerFor
annotation is an interesting annotation available from JSF 2.0. This annotation allows a component to subscribe to particular events with the component itself being the listener. For this, we need to follow the ensuing steps:
Implement the
ComponentSystemEventListener
interface (the name indicates that the event will always be associated with aUIComponent
instance).Override the
processEvent
method (here we can play with the component).Use the
@ListenerFor
to indicate the event that the UI component will subscribe for, and the source class of the UI component.
For example, the UIInput
component can subscribe to the PostAddToViewEvent
event for adding attributes to the component, for example, following is a case, where we add some CSS to each UIInput
component:
@ListenerFor(systemEventClass = PostAddToViewEvent.class, sourceClass = javax.faces.component.UIInput.class) public class PlayerRenderer extends TextRenderer implements...