SashikaXP
SashikaXP

Reputation: 817

@ManagedProperty is not injected

@ManagedProperty("#{sessionBean}") is not injected properly. The sessionBean is declared in a JAR file and it has a JSF 2.0 compatible faces-config as well. But when I use

FacesContext context = FacesContext.getCurrentInstance();
sessionBean = (SessionBean) context.getApplication().evaluateExpressionGet(context, "#{sessionBean}", SessionBean.class);

It evaluates the session bean correctly. What is the reason?

EDIT: The bean that I want to be injected(sessionBean) is in a JAR file which is annotated as @ManagedBean and @SessionScoped. Also the JAR contains a JSF2 compatible faces-config in the META-INF/resources

Upvotes: 3

Views: 2618

Answers (2)

klonq
klonq

Reputation: 3587

For me this was an issue with packages, the following imports worked for me:

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;

Before I was using a combination of different packages (auto-imported by IDE):

import javax.faces.bean.ManagedProperty;
import javax.faces.view.ViewScoped;
import javax.inject.Named;

Upvotes: 1

Manuel
Manuel

Reputation: 4228

1.) Where are you injecting the sessionBean into? Show us the class definition. Is the class a @ManagedBean?

2.) Check if the setter setSessionBean(SessionBean sb) called.

3.) Is the provided value in the setter null?

4.) You can also try to do the following:

@PostConstruct
private void init() {
  FacesContext context = FacesContext.getCurrentInstance();
  sessionBean = (SessionBean) context.getApplication().evaluateExpressionGet(context, "#{sessionBean}", SessionBean.class);
}

... and check if the sessionBean is evaluated correctly.

Upvotes: 1

Related Questions