HTML and CSS Reference
In-Depth Information
whose key is PROFESSIONS_KEY in the application map. In the PreDestroyApplicationEvent , any possible cleanup
can be performed; in our listener, the profession list is just removed from the application map.
In order to allow our application's custom SystemEvent listener to execute in PostConstructApplicationEvent
or PreDestroyApplicationEvent , we need to register our custom SystemEvent listener in the faces configuration file
(faces-config.xml), as shown in Listing 4-21.
Listing 4-21. Registering Our Custom SystemEvent Listener in faces-config.xml
<faces-config ...>
<application>
<system-event-listener>
<system-event-class>javax.faces.event.PostConstructApplicationEvent</system-event-class>
<system-event-listener-class>com.jsfprohtml5.subscriber.model.ListingLoader
</system-event-listener-class>
</system-event-listener>
<system-event-listener>
<system-event-class>javax.faces.event.PreDestroyApplicationEvent</system-event-class>
<system-event-listener-class>com.jsfprohtml5.subscriber.model.ListingLoader
</system-event-listener-class>
</system-event-listener>
...
</application>
</faces-config>
Using the <system-event-listener> element inside the <application> element, we can register a System event
listener on a specific System event. It has two main elements: the <system-event-class> element, which represents
the fully qualified class name of the System event class, and the <system-event-listener-class> element, which
represents the fully qualified class name of the System event listener class.
In our example, we declare two <system-event-listener> elements to allow our custom SystemEvent listener
( ListingLoader ) to receive events from both PostConstructApplicationEvent and PreDestroyApplicationEvent .
there is an optional element under the <system-event-listener> , which is <source-class> element. the
<source-class> element can be used for specifying the fully qualified class name of the event source.
Note
Now that we see an example of System events that can occur on the application level, let's see how to utilize the
System events that can occur on the component level. Assume that we want to customize the error displaying way on
the input fields of the subscriber application form so that when we have an error (or set of errors) in the validation,
then input fields will be highlighted. This is actually a perfect use case for component System events. In order to
implement this use case, we will need to utilize the postValidate event.
JSF introduces <f:event> tag that we can put directly as a child of any JSF HTML component in order to install
ComponentSystemEventListener instances on it. Table 4-4 shows the attributes of <f:event> tag. Notice that the
mentioned attributes of <f:event> tag are mandatory.
 
 
Search WWH ::




Custom Search