You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by "Jakob Korherr (JIRA)" <de...@myfaces.apache.org> on 2009/12/03 13:14:20 UTC

[jira] Commented: (MYFACES-2396) @PreDestroy method of Bean in CustomScope not invoked

    [ https://issues.apache.org/jira/browse/MYFACES-2396?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12785283#action_12785283 ] 

Jakob Korherr commented on MYFACES-2396:
----------------------------------------

This issue is _REALLY_ weird. I spent a lot of time investigating this Exception and now (I think), I finally found it.

The problem comes from the following method of Application.java

public void subscribeToEvent(Class<? extends SystemEvent> systemEventClass, SystemEventListener listener)
    {
        Application application = getMyfacesApplicationInstance();
        if (application != null)
        {
            application.subscribeToEvent(systemEventClass, listener);
            return;
        }
        subscribeToEvent(systemEventClass, null, listener);
    }

It tries to get the actual MyFacesApplicationInstance (ApplicationImpl) from the ApplicationMap. This method returns null, if either FacesContext is null, ExternalContext is null or ApplicationFactoryImpl did not put it in the ApplicationMap yet.

If the call to getMyfacesApplicationInstance() returns NULL (!!!), everything functions properly and we can never get an infinite loop. Otherwise it calls subscribeToEvent(Class<? extends SystemEvent> systemEventClass, SystemEventListener listener) on ApplicationImpl, which is not overrided and thus it calls itself again and again.

Normally this functions properly, because at startup FacesContext and ExternalContext are null. I don't really know how, but if you (or the Tomcat) managed to initialise the FacesContext and the ExternalContext before subscribeToEvent is invoked, we ran into the infinte loop.

The solution is, of course, really easy, but it was a long way to get there....

> @PreDestroy method of Bean in CustomScope not invoked
> -----------------------------------------------------
>
>                 Key: MYFACES-2396
>                 URL: https://issues.apache.org/jira/browse/MYFACES-2396
>             Project: MyFaces Core
>          Issue Type: Bug
>          Components: JSR-314
>            Reporter: Jakob Korherr
>            Assignee: Leonardo Uribe
>         Attachments: myfaces-2396-final.patch, myfaces_2396_proposal.patch
>
>
> Testing the mojarra 2.0.1 sample "custom-bean-scope", MyFaces does NOT behave like Mojarra.
> The problem is that MyFaces does not propagate a PreDestroyCustomScopeEvent correctly. The following code is from the mojarra sample and shows how the event is published:
> public void notifyDestroy() {
>             // notify interested parties that this scope is being
>             // destroyed
>             ScopeContext scopeContext = new ScopeContext(SCOPE_NAME, this);
>             application.publishEvent(FacesContext.getCurrentInstance(), PreDestroyCustomScopeEvent.class, scopeContext);
> }
> However, the @PreDestroy method of the Bean, which is stored in the scope, is not invoked.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.