webtier@glassfish.java.net

Re: [webtier] Custom Scope : How is it working ?

From: Edward Burns <edward.burns_at_oracle.com>
Date: Fri, 02 Jul 2010 08:19:57 -0400

On 7/2/10 3:01 , webtier_at_javadesktop.org wrote:
> yes I did ... it was the only useful ressource I found, but it still doesn´t answer my questions.
>
> What has to be IN this map I am referring to ?
> Or : how do I specify when to invalidate a session ?

Let's define some terms first.

scope

    A dictionary data structure into which managed beans are stored.

scope name

    The name of a data structure into which are stored
    managed beans that declare they belong in that scope.

    for example, request, session, application, view,
    #{controller.foo}, #{store.bar}, #{manager.baz} etc.

scope lifetime

    The amount of time managed beans that are stored in a scope
    are considered valid and are guaranteed not to be garbage
    collected.

With any of the named scopes (request, session, etc) the scope lifetime
is predefined by the specification.

With a custom scope, you, the developer, are telling the framework
"evaluate the expression #{store.foo}" and treat the result as a Map.
Therefore, the logic in the managed bean can control the lifetime. Like
this:

@ManagedBean
public class Store {
   public Map getFoo() {
     // Determine if I need to create a new map, if so, create it.
     // return the Map; Perhaps an inner class is useful.
   }
}

Because the Store class is called whenever a managed bean needs to be
obtained or stored, the Map it returns can call clear() on itself
whenever it needs to.

Does that help?

Ed