Skip to main content

Custom Scope : How is it working ?

5 replies [Last post]
danielbreitner
Offline
Joined: 2010-06-25

Hello everybody,

I have a simple question about the CustomScope feature of JSF 2.0.

I understood, that I can set my Backing Bean to CustomScope which is essentially a Map, right ?

So, the question that I have is : what should be insider this map ?
Is there a really complex example out there ?

with kind regards

daniel

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Edward Burns

On 7/1/10 4:34 , webtier@javadesktop.org wrote:
> Hello everybody,
>
> I have a simple question about the CustomScope feature of JSF 2.0.
>
> I understood, that I can set my Backing Bean to CustomScope which is essentially a Map, right ?
>
> So, the question that I have is : what should be insider this map ?
> Is there a really complex example out there ?

Have you seen this already?

http://blogs.sun.com/rlubke/entry/custom_managed_bean_scopes

Ed

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

danielbreitner
Offline
Joined: 2010-06-25

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 ?

Edward Burns

On 7/2/10 3:01 , webtier@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

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

danielbreitner
Offline
Joined: 2010-06-25

ok, now I understand it - Thank you very much !!!

Could you give a little insight into how to detect page forwards, new views etc. ?
So how would you clean the map ?

With kind regards,

daniel

Edward Burns

On 7/5/10 9:29 , webtier@javadesktop.org wrote:
> ok, now I understand it - Thank you very much !!!
>
> Could you give a little insight into how to detect page forwards, new views etc. ?
> So how would you clean the map ?

Because JSF 2.0 includes facelets, make every page apply a template that
has the f:event tag that declares a PreRenderView event listener. In
there, you can track such things.

Ed

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net