Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6922365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:23:48+00:00 2026-05-27T10:23:48+00:00

I instantiated a request bean from another request bean, new LoginManager(); But the property

  • 0

I instantiated a request bean from another request bean,

new LoginManager();

But the property which is annotated with @ManagedProperty doesn’t get the value from the asked reference, only in case of instantiation through the above way. It just contains null, causing NPE later in code. Also @PostConstruct won’t be invoked. Why is it so & how should I deal with this?

@ManagedBean(name = "loginManager")
@RequestScoped
public class LoginManager {

    private String userid;
    private String password;

    @ManagedProperty(value="#{currentSession}")
    private UserSessionManager userSession;

}

But userSession can’t read from the session scoped bean when this bean was instantiated using: new LoginManager();

However I can read the value using FacesContext!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:23:49+00:00Added an answer on May 27, 2026 at 10:23 am

    You should not manually instantiate (manage) beans using new operator. You should let JSF do the job of managing the beans and instead grab the JSF-managed (JSF-instantiated) instance.

    Either by @ManagedProperty in the bean where you need it:

    @ManagedProperty("#{loginManager}")
    private LoginManager loginManager;
    

    Or by invoking EL programmatically (which is pretty borderline in your particular case):

    LoginManager loginManager = context.getApplication().evaluateExpressionGet(context, "#{loginManager}", LoginManager.class);
    // ...
    

    If you insist in instantiating and managing the bean yourself, you should do all dependency injections yourself, also invoking the @PostConstruct yourself, if any, and finally also putting the bean in the desired scope yourself. E.g.

    LoginManager loginManager = new LoginManager();
    loginManager.setUserSession(userSession);
    // Now use reflection to find and invoke @PostConstruct method.
    // Finally store in the map which conforms the bean's scope.
    externalContext.getRequestMap().put("loginManager", loginManager);
    

    This boilerplate is exactly what JSF is supposed to take away from your hands. Make use of it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to instantiate a session bean from another request scoped bean & set
I am using a @ManagedBean (request scoped) as a @ManagedProperty inside another @ManagedBean .
Given an instantiated JavaScript object/class can I make an Ajax call from that class
The object I’m working on is instantiated in JavaScript, but used in VBScript. In
I am using a System.Random object which is instantiated with a fixed seed all
In repository examples, I see the repository instantiated when the Session opens, which seems
Oh hai I have an ajax request, which works way: request starts: tinyMCE gets
I have defined a UIWebViewDelegate class and instantiated it in the Delegate property of
I have a wrapper class (BluetoothDiscoverer) which is instantiated within a Service. This class
I have a class instantiated like so in my applicationContext.xml: <bean id=class1 class=com.action.abc.class1 scope=session

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.