Note that there are some explanatory texts on larger screens.

plurals
  1. POJSF Static Bean Variable Scope
    primarykey
    data
    text
    <p>So, I've seen this post: <a href="https://stackoverflow.com/questions/1770610/jsf-session-scoped-bean-shared-by-browsers-on-different-machines">JSF - session scoped bean shared by browsers on different machines</a></p> <p>But this was a question from two years ago, so I don't know if there have been any updates in the world of JSF since then, and I also have some more specific cases to which I'd seek clarification. Basically, what I'd like to know is how static scope variables are handled in beans with different scopes. For example:</p> <pre><code>@ManagedBean @ApplicationScoped public class ApplicationBean{ static private int someStaticInt=0; ... } </code></pre> <p>Since this bean is Application scoped, I would completely expect someStaticInt to be shared by all users of the app, i.e. user A sets the value to 3, all users would henceforth see that value as 3. Correct me if I'm wrong.</p> <p>But what about this scenario:</p> <pre><code>@ManagedBean @ViewScoped public class ViewScopeBean{ static private int staticInt = 0; private SomePOJO myClass; ... public void someAction(){ SomePOJO.memberStaticInt++; ... } } ... public SomePOJO{ static private int memberStaticInt = 0; ... } </code></pre> <p>Now, this bean is ViewScoped, so there's a separate instance for each user of the application. But what about that static int? If I increment that, is it only going to be within MY instance of the Bean, or is it going to be incremented for all users. Furthermore, what about that member object, myClass? It's not declared static in the bean, but it has a static member itself. If I run someAction, will memberStaticInt be incremented for all users or just the user using that instance of the Bean?</p> <p>Finally, I'd be interested to know if any and all such logic in the above cases also applies to RequestScoped beans.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload