myfaces-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Leonardo Uribe (JIRA)" <...@myfaces.apache.org>
Subject [jira] [Commented] (MYFACES-4047) @PreDestroy method not invokved on javax.faces.bean.ViewScoped beans on Session invalidation
Date Fri, 20 May 2016 00:56:13 GMT

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

Leonardo Uribe commented on MYFACES-4047:
-----------------------------------------

I have checked the patch and I notice a direct call will not work because facesContext.getViewRoot()
is null at session expiration (on session expiration you are calling PreDestroy of beans related
to many views at once). We need to find another way to do it, and I have remembered more details
that we need to discuss.

The problem is there are two cases to take into account:

- The servlet container call ManagedBeanDestroyerListener.sessionDestroyed(...) and then it
calls ViewScopeProvider.onSessionDestroyed(...)
- ViewScopeBeanHolder (which is a CDI session scope bean) receives a PreDestroy call on destroyBeansOnPreDestroy()

There is a comment in the code which says:

{code:java}
        // After some testing done two things are clear:
        // 1. jetty +  weld call @PreDestroy at the end of the request
        // 2. use a HttpServletListener in tomcat + owb does not work, because
        //    CDI listener is executed first.
        // So we need a mixed approach using both a listener and @PreDestroy annotations.
        // When the first one in being called replace the storages with a new map 
        // and call PreDestroy, when the second one is called, it founds an empty map
        // and the process stops. A hack to get ServletContext from CDI is required to
        // provide a valid FacesContext instance.
{code}

The logic is if CDI listener is on top, PreDestroy of ViewScopeBeanHolder will be called first
(we can't wait to myfaces listener because it will be too late). So after this reasoning,
the code should be in ViewScopeBeanHolder, not in CDIManagedBeanHandlerImpl, and it is not
possible to use the listener, so we are forced to call ManagedBeanDestroyer directly.

It looks like the algorithm for DefaultViewScopeHandler.onSessionDestroyed() needs some work.
Let me think about it, I'll propose a patch so we can discuss it.

> @PreDestroy method not invokved on javax.faces.bean.ViewScoped beans on Session invalidation
> --------------------------------------------------------------------------------------------
>
>                 Key: MYFACES-4047
>                 URL: https://issues.apache.org/jira/browse/MYFACES-4047
>             Project: MyFaces Core
>          Issue Type: Bug
>          Components: JSR-344
>    Affects Versions: 2.2.10
>            Reporter: Paul Nicolucci
>            Priority: Minor
>         Attachments: myfaces-4047.patch
>
>
> Consider the following scenario:
> Bean1:
> @Named
> @ViewScoped (javax.faces.view.ViewScoped)
> Bean2:
> @ManagedBean
> @ViewScoped (javax.faces.bean.ViewScoped)
> When the session is invalidated the org.apache.myfaces.cdi.impl.CDIManagedBeanHandlerImpl.onSessionDestroyed()
method is invoked. Here, MyFaces destroys all of the javax.faces.view.ViewScoped @Named beans
and @PreDestroy is invoked on these beans. However, the @ManagedBean /ViewScoped bean does
not have its @PreDestroy invoked.
> I believe this is because the assumption was made that if an Application is CDI enabled
it will contain all CDI @Named beans and not any @ManagedBeans. There is also the DefaultViewScopeHandler
which is not yet implemented for "onSessionDestroyed" that would be used in the case when
CDI is not enabled, that is when only @ManagedBeans are contained in the application.
> I believe it is possible to update the CDIManagedBeanHandlerImpl to be aware of the ViewScoped
ManagedBeans and destroy them onSessionDestroy first by just getting the viewMap and iterating
over the entries as we do when the PreDestroyViewMapEvent is processed.
> I'd like to use this issue to resolve the problem in CDIManagedBeanHandlerImpl as well
as implement onSessionDestroy in DefaultViewScopeHandler.java



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message