0

We can put whole bean in sessionScope.

<managed-bean>
  <managed-bean-name>managedBeanList</managed-bean-name>
  <managed-bean-class>com.org.SomeMBean</managed-bean-class>
  <managed-bean-scope>session</managed-bean-scope>

But is there anything like we can put only a field of that managed bean in sessionScope?

like...

public class SomeMBean{

public String mySessionScopeVariable; // Is there any way only this field will be in sessionscope continusly and not whole bean.

//getter setter of that variable.
}
Thihara
  • 7,031
  • 2
  • 29
  • 56
Ketan Bhavsar
  • 5,338
  • 9
  • 38
  • 69

2 Answers2

4

No this is not possible.

You should separate the field in a separate session scoped bean and use @ManagedProperty to inject it into your narrower scoped bean.

Matt Handy
  • 29,855
  • 2
  • 89
  • 112
  • Hummmmn looks like this... JSF future version must have this kind of things... ;) By the way thanks a lot for reply... – Ketan Bhavsar May 04 '12 at 07:26
  • 1
    @SoftwareGuruji: No, that's not necessary. You're just making a thinking fault. Putting session scoped data in a separate session scoped managed bean makes design technically perfectly sense. See also http://stackoverflow.com/questions/7031885/how-to-choose-the-right-bean-scope – BalusC May 04 '12 at 13:28
1

I don't see how. I'm no expert on JSF but to access an attribute in the ManagedBean or any bean for that matter one would need the bean since the attribute cannot exist without the bean. If you are thinking that your managed bean is bloating the session size set the heavy variables to null to save the memory. But apart from that i don't see any other way.

Thihara
  • 7,031
  • 2
  • 29
  • 56
  • Yup! My managemd bean having lot of thing. If I put it into session scope that will use my memory alot... :( By the way thanks a lot for reply... – Ketan Bhavsar May 04 '12 at 07:27