tags:

views:

31

answers:

1

hi,

could some explain what a none scope is and purpose of it?

Suppose if i have a bean in

request scope as r1

session scope as s1

application scope a1

and say i inject none scope bean n1 in to each of above scopes then i find that n1 gets instantiated for each parent bean when ever its parent bean[r1/s1/a1] is instantiated.

none scope bean in a1 is available throughout in a1 since a1 is appl scope. none scope bean in s1 is available only until s1 is not destroyed and when s1 is created again n1 is instanciated and made available to it.

Is it correct?

and what the purpose of using it? only to avoid creating such bean our self?

many thanks

+1  A: 

A bean with a <managed-bean-scope> of none or a @NoneScoped annotation will be created on demand whenever the view requires it. It won't be stored anywhere. E.g. the following in the view

<p>#{bean.text}</p>
<p>#{bean.text}</p>
<p>#{bean.text}</p>

on a none-scoped bean will construct the bean 3 (three) times during a request. Every access to the bean gives a completely separate bean which is been garbaged immediately after the property access.

I have never used it before. I however can see benefits when it's a managed property which is not per-se loaded during every request. I don't see any benefits of it as far.


Update: this scope may be useful when you'd like to define and declare managed properties in the faces-config.xml rather than directly in the parent bean itself. It has more a documentatory purpose and it also gives more easy control to change the bean implementation of the managed property (if declared as an abstract/interface type).

BalusC
@BalusC: i didn't get the benefit you have mentioned ...could you please elaborate a bit...
daedlus
@deadlus: by coincidence, I just started to play somewhat with it after I posted the answer. Sorry, it didn't work as I expected and I don't see any benefits anymore.
BalusC