aspose file tools*
The moose likes JSF and the fly likes How get session mb in POJO? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "How get session mb in POJO?" Watch "How get session mb in POJO?" New topic
Author

How get session mb in POJO?

Michał Jurczuk
Greenhorn

Joined: Apr 27, 2009
Posts: 5
i have in faces-config.xml:

when I try:

uh is null

How can I get utilHibernate in POJO??
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15632
    
  15

I'll bet if you called getSession with false it would throw a NullPointerException.

Session Managed beans are constructed on-demand, not at session create time. If you don't yet have a session, or the JSF framework hasn't yet requested that object, it won't exist yet.

If so, you can always construct your own session and session scoped object. JSF won't care. It will still use the session object you've created as though it had created the object itself.

In the case of managed beans with injected properties, you may prefer to ask JSF to construct the managed bean for you so that it will apply the rules defined in the faces-config file. You'll have to look up how to do that - I don't have that info handy.

But in your case, there's nothing in faces-config that you can't do by hand. Either way works.


Customer surveys are for companies who didn't pay proper attention to begin with.
Michał Jurczuk
Greenhorn

Joined: Apr 27, 2009
Posts: 5
thanks
The problem was as you said mb are constructed on-demand. I create a new session object and now everything is working properly
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How get session mb in POJO?
 
Similar Threads
JSF backingbean value is null always.
managed bean injection problem
Not creating managed bean
Accessing jsf bean from another jsf bean
Obtaining an instance of a Managed Bean declared with Application Level Scope