Annotation Type ListenerFor
-
@Retention(RUNTIME) @Target(TYPE) @Inherited @Repeatable(ListenersFor.class) public @interface ListenerFor
Classes tagged with this annotation are installed as listeners using the method
Application.subscribeToEvent(java.lang.Class<? extends jakarta.faces.event.SystemEvent>, java.lang.Class<?>, jakarta.faces.event.SystemEventListener)orUIComponent.subscribeToEvent(java.lang.Class<? extends jakarta.faces.event.SystemEvent>, jakarta.faces.event.ComponentSystemEventListener)(depending on the circumstances, described below).The default implementation must support attaching this annotation to
UIComponentorRendererclasses. In both cases, the annotation processing described herein must commence during the implementation of any variant ofApplication.createComponent()and must complete before theUIComponentinstance is returned fromcreateComponent(). The annotation processing must proceed according to an algorithm semantically equivalent to the following.-
If this annotation is not present on the class in question, no action must be taken.
Determine the "target" on which to call
subscribeToEvent.If the class to which this annotation is attached implements
ComponentSystemEventListenerand is aUIComponentinstance, "target" is theUIComponentinstance.If the class to which this annotation is attached implements
ComponentSystemEventListenerand is aRendererinstance, "target" is theUIComponentinstance that is to be rendered by thisRendererinstance.If the class to which this annotation is attached implements
ComponentSystemEventListenerand is neither an instance ofRenderernorUIComponent, the action taken is unspecified. This case must not trigger any kind of error.If the class to which this annotation is attached implements
SystemEventListenerand does not implementComponentSystemEventListener, "target" is theApplicationinstance. -
Determine the variant of
subscribeToEvent()to call and the parameters to pass to it.If "target" is a
UIComponentcallUIComponent.subscribeToEvent(Class, ComponentSystemEventListener), passing thesystemEventClass()of the annotation as the first argument and the instance of the class to which this annotation is attached (which must implementComponentSystemEventListener) as the second argument.If "target" is the
Applicationinstance, inspect the value of thesourceClass()annotation attribute value.If the value is
Void.class, callApplication.subscribeToEvent(Class, SystemEventListener), passing the value ofsystemEventClass()as the first argument and the instance of the class to which this annotation is attached (which must implementSystemEventListener) as the second argument.Otherwise, call
Application.subscribeToEvent(Class, Class, SystemEventListener), passing the value ofsystemEventClass()as the first argument, the value ofsourceClass()as the second argument, and the instance of the class to which this annotation is attached (which must implementSystemEventListener) as the third argument.
Example: The standard renderer for
jakarta.faces.resource.Stylesheetmust have the following annotation declaration:@ListenerFor(systemEventClass=PostAddToViewEvent.class)This will cause the renderer to be added as a listener for the
PostAddToViewEventto all components that list it as their renderer.- Since:
- 2.0
-
-
-
Required Element Summary
Required Elements Modifier and Type Required Element Description Class<? extends SystemEvent>systemEventClassThe kind of system event for which this class will be installed as a listener.
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description ClasssourceClassThe kind of object that emits events of the type given by the value of thesystemEventClass()attribute.
-
-
-
Element Detail
-
systemEventClass
Class<? extends SystemEvent> systemEventClass
The kind of system event for which this class will be installed as a listener. The implementation only supports exact matches on the
Classand must not honor subclass relationships. It is valid to have EL Expressions in the value of this attribute, as long as the expression resolves to an instance of the expected type.- Returns:
- the event class
-
-
-
sourceClass
Class sourceClass
The kind of object that emits events of the type given by the value of the
systemEventClass()attribute. It is valid to have Jakarta Expression Language Expressions in the value of this attribute, as long as the expression resolves to an instance of the expected type.- Returns:
- the source class
- Default:
- java.lang.Void.class
-
-