Saturday, July 14, 2012


Custom Scope : How is it working ?




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.

No comments: