Hi

Could you please provide an example to test this stuff properly? The
problem in this point is these lines in the javadoc of
javax.faces.view.ViewScope:

"... In the session expiration case, the runtime must ensure that
FacesContext.getCurrentInstance() returns a valid instance if it is called
during the processing of the @PreDestroy annotated method. The set of
methods on FacesContext that are valid to call in this circumstance is
identical to those documented as "valid to call this method during
application startup or shutdown". On the ExternalContext returned from that
FacesContext, all of the methods documented as "valid to call this method
during application startup or shutdown" are valid to call. In addition, the
method ExternalContext.getSessionMap() is also valid to call. ..."

So if we use a @PreDestroy on
org.apache.myfaces.cdi.view.ViewScopeBeanHolder, CDI has the control and we
can't warrant FacesContext to be available. So we had to do the workaround
using ManagedBeanDestroyer (it implement HttpSessionListener). We have this
code:

    public void onSessionDestroyed()
    {
        // In CDI case, the best way to deal with this is use a method
        // with @PreDestroy annotation on a session scope bean
        // ( ViewScopeBeanHolder.destroyBeans() ). There is no need
        // to do anything else in this location, but it is advised
        // in CDI the beans are destroyed at the end of the request,
        // not when invalidateSession() is called.
        FacesContext facesContext = FacesContext.getCurrentInstance();
        if (facesContext != null)
        {

I suppose what's going on there is in the context the session invalidation
is done, FacesContext is null and @PreDestroy is ignored.

To be clear two questions:

1. Is manual session expiration working ? I suppose yes.
2. Is session invalidation by a timeout working ? I suppose no.

regards,

Leonardo Uribe



2013/10/17 Howard W. Smith, Jr. <[email protected]>

> On Thu, Oct 17, 2013 at 8:53 PM, Howard W. Smith, Jr. <
> [email protected]> wrote:
>
> > Clarification: my test included session.invalidate() instead of (actual)
> > session expired (via/after session timeout).
> >
> > will provide test (config, steps and) results in my next response to this
> > thread.
> >
>
> i tested my app with latest MyFaces 2.2.0 snapshot (2013-Oct-17) with TomEE
> 1.6.0 snapshot (2013-Oct-10; myfaces comitter said that myfaces 2.2.0
> snapshots works with this version of tomee 1.6.0 snapshot),
>
> removed myfaces 2.1.12 JARs from tomee/lib, and dropped myfaces 2.2.0 JARs
> in tomee/lib
>
> modified one of my beans, replaced OmniFaces CDI @ViewScoped with MyFaces
> 2.2.0 CDI @ViewScoped (javax.faces.view.ViewScoped)
>
> generated WAR, deployed WAR to tomee/webapps, started tomee, and started
> test(ing)
>
>
> - navigated to page which references (myfaces 2.2.0 CDI @ViewScoped);
> @PostConstruct executed
>
> Oct 17, 2013 7:33:56 PM jsf.orders.OrderDocumentBean init
> INFO: jsf.orders.OrderDocumentBean@3273c362
>
> - navigated away from that page (action="index.xhtml", non-null outcome);
> @PreDestroy executed
>
> Oct 17, 2013 7:34:30 PM jsf.orders.OrderDocumentBean releaseResources
> INFO: jsf.orders.OrderDocumentBean@3273c362
>
> - navigated to page which references (myfaces 2.2.0 CDI @ViewScoped)
>
> Oct 17, 2013 7:35:22 PM jsf.orders.OrderDocumentBean init
> INFO: jsf.orders.OrderDocumentBean@214e2561
>
> - navigated away from that page (action = null outcome), bean not destroyed
> (of course)
> - navigated to another page (action="index.xhtml", non-null outcome), bean
> destroyed
>
> Oct 17, 2013 7:35:35 PM jsf.orders.OrderDocumentBean releaseResources
> INFO: jsf.orders.OrderDocumentBean@214e2561
>
> - navigated to page which references (myfaces 2.2.0 CDI @ViewScoped)
>
> Oct 17, 2013 7:35:50 PM jsf.orders.OrderDocumentBean init
> INFO: jsf.orders.OrderDocumentBean@28a78a2c
>
> - pressed F5/refresh in Google Chrome, new bean created and page does not
> render data anymore :(
>
> Oct 17, 2013 7:36:11 PM jsf.orders.OrderDocumentBean init
> INFO: jsf.orders.OrderDocumentBean@7af07081
>
> - logged out user (session.invalidate() is executed, @PreDestroy not
> executed to show that the beans were destroyed)
>
> Oct 17, 2013 7:36:39 PM jsf.users.pf_UsersController logout
> INFO: administrator logged out at 10/17/2013 07:36 PM
>
> - but checked jvisualvm (heap dump) and 0/zero/no instances of CDI
> @ViewScoped bean exist
>
> OmniFaces CDI @ViewScoped[1] executes @PreDestroy on session.invalidate()
> and that is what I like/expect, but MyFaces 2.2 CDI @ViewScoped
> implementation is not doing the same.
>
> so, is omnifaces (and mojarra 2.2) CDI @ViewScoped 'spec-compliant', or is
> this an added feature of OmniFaces, to execute @PreDestroy before CDI
> @ViewScoped bean is destroyed on session.invalidate()?
>
>
> [1] https://code.google.com/p/omnifaces/issues/detail?id=201
>

Reply via email to