// subscribe ManagedBeanDestroyer as listener for needed events
application.subscribeToEvent(PreDestroyCustomScopeEvent.class, mbDestroyer);
application.subscribeToEvent(PreDestroyViewMapEvent.class, mbDestroyer);
// get ManagedBeanDestroyerListener instance
ManagedBeanDestroyerListener listener = (ManagedBeanDestroyerListener)
applicationMap.get(ManagedBeanDestroyerListener.APPLICATION_MAP_KEY);
if (listener != null)
{
// set the instance on the listener
listener.setManagedBeanDestroyer(mbDestroyer);
}
else
{
log.log(Level.SEVERE, "No ManagedBeanDestroyerListener instance found, thus "
+ "@PreDestroy methods won't get called in every case. "