0

EDIT: This is an ADF application which uses JSF 2.0.

I have an application-scoped managed bean which I am referencing in the managed property of a request-scoped bean. I am getting a NullPointerException when trying to access the app-scoped bean within the PostConstruct method of the request-scoped bean. I am not sure whether I am not understanding some fundamentals about when an app-scoped bean is available to a request-scoped bean, or whether I just have a mistake in my implementation.

App-scoped bean:

@ManagedBean(eager=true)
@ApplicationScoped
public class SecurityApplication {

    public String test() {
        return "test result";
    }

    @PostConstruct
    public void init() {
        System.out.println("In SecurityApplication.init");
    }
}

EDIT: This is configured as a request-scoped managed bean in the adfc-config.xml file. This appears to be the problem since I have specified that the bean be managed by ADF, but used the JSF ManagedProperty annotation.

Request-scoped bean:

public class UserSecurityCompanies {
    @ManagedProperty(value="#{securityApplication}")
    private SecurityApplication securityApplication;

    @PostConstruct
    public void init() {
        System.out.println("In UserSecurityCompanies.init");
        System.out.println("SecurityApp.Test():" + getSecurityApplication().test());
    }

    public SecurityApplication getSecurityApplication() {
        return securityApplication;
    }

    public void setSecurityApplication(SecurityApplication securityApplication) {
        this.securityApplication = securityApplication;
    }
}

The app-scoped bean is initialized during deployment of the app, but the NPE is thrown when getSecurityApplication().test() is called.

Steve

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Steve
  • 91
  • 10
  • You left out one ambiguity. Who's managing that request scoped bean? If it's not JSF `@ManagedBean`, then `@ManagedProperty` obviously won't have any effect. – BalusC Dec 03 '15 at 16:59
  • @BalusC - Thanks, I think that is pointing to the problem. I am using ADF which suggests that you configure beans in adfc-config.xml. I had the request scoped bean specified as a managed bean in that file, but the managed property is as shown above. I changed it so that it not registered as an ADF managed bean, but is a pure JSF ManagedBean and now I no longer get the NPE. So, it sounds like that solved that problem. I am however, getting other errors with ADF components not seeing properties in this bean, which makes me think mixing ADF with pure JSF managed beans is going to be a problem. – Steve Dec 03 '15 at 17:23
  • Have edited the original post to show what the problem was. – Steve Dec 03 '15 at 17:33
  • Bean is merely java class and its stay so regardless of framework, however managing adf framework in some other framework way is a real problem. You should give more explanation of what you doing and what you are trying to achieve. Also provide version of ADF you are using. – Nagh Dec 07 '15 at 03:31
  • I think the real question is why you would like to use JSF 'only' managed beans instead of the ADF 'only' beans while using ADF. – User404 Dec 09 '15 at 06:35

0 Answers0