• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSF sessionScope and storing values

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just a doubt regarding how JSF session management works

I got a managedbean as :



So now since the bean is sessionScoped, will JSF store my "userBO" object in the session too? Or do I have to declare "userBO" as transient so that it is ignored?
I believe that variables with both the setters and getters are likely to be stored in the session. Correct me if I am wrong.

Thanks
 
Akshat Joshi
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anyone...any thoughts? :/
 
Saloon Keeper
Posts: 27764
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First thought: Have Patience. We're not paid to sit here 24x7, so it can take a day or 2 to get an answer. It's the down side of free help.

Second thought: Standarddisclaimerthatuser-createdloginsareBAD. I rant about this often enough, I'll spare people a repeat. Please consider using J2EE standard Form-based logins instead.

Now the Real Answer.

There is no "userBO" object created by this bean. The value "#{userBO}" is a Unified Expression Language predicate. In other words, it's an expression in EL that references a Java object that was defined in the EL dictionary under the name of "userBO". When applied to a ManagedProperty annotation, it provides the JSF bean manager with a reference to a bean to inject. You have to construct and define userBO to the EL system yourself in an external definition. Typically that means either defining UserBO as a ManagedBean itself via its own annotations or a faces-config.xml definition, but other sources such as the Spring Framework can also supply named beans that EL can reference, too.

Java has no implied accessor/mutator mechanism, and it is not recommended that Managed Bean properties (or for that matter, any POJO properties) be declared as public. So you must manually create the required set/get methods. Fortunately, most IDEs have a "one-button" mechanism to construct the necessary Java code automatically.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic