The @ListenerFor
is supposed to be set on an UIComponent
or Renderer
implementation, not on a standalone SystemEventListener
implementation. See also the javadoc (emphasis mine):
The default implementation must support attaching this annotation to
UIComponent
orRenderer
classes. In both cases, the annotation processing described herein must commence during the implementation of any variant ofApplication.createComponent()
and must complete before theUIComponent
instance is returned fromcreateComponent()
. The annotation processing must proceed according to an algorithm semantically equivalent to the following....
In order to have a global listener, not specific to an UIComponent
or Renderer
, your best bet is creating and registering a PhaseListener
which subscribes the listener to the view root.
public class PostValidateListener implements PhaseListener {
@Override
public PhaseId getPhaseId() {
return PhaseId.PROCESS_VALIDATIONS;
}
@Override
public void beforePhase(PhaseEvent event) {
event.getFacesContext().getViewRoot()
.subscribeToViewEvent(PostValidateEvent.class, new InputPostValidationListener()); // Capitalize class name?
}
@Override
public void afterPhase(PhaseEvent event) {
// NOOP.
}
}
To get it to run, register it as follows in faces-config.xml:
<lifecycle>
<phase-listener>com.example.PostValidateListener</phase-listener>
</lifecycle>
You can even make your InputPostValidationListener
itself a PhaseListener
.
public class InputPostValidationListener implements PhaseListener, SystemEventListener {
@Override
public void beforePhase(PhaseEvent event) {
event.getFacesContext().getViewRoot().subscribeToViewEvent(PostValidateEvent.class, this);
}
// ...
}