I'm trying to inject a Managed Property into my class, but every time I try to access it in a method annotated with @PostConstruct
it returns null, thus generating an Exception.
Below is my class:
package br.com.pathfind.importacao.managedbean;
import java.io.Serializable;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import br.com.lantech.pathfind.corporativo.service.ParametroService;
import br.com.lantech.pathfind.model.Parametro;
import br.com.lantech.pathfind.model.exception.PathfindException;
@ManagedBean(name = "importarArquivoBean")
@ViewScoped
public class ImportarArquivoBean implements Serializable {
private static final long serialVersionUID = 1L;
private Parametro parametroERP;
@ManagedProperty("#{parametroService}")
private ParametroService parametroService;
private boolean promax;
@PostConstruct
private void inicializar() {
//parametroService retornando nulo.
try {
parametroERP = parametroService.recuperaPorDescricao("ERP");
} catch (PathfindException e) {
e.printStackTrace();
}
promax = false;
if (parametroERP.getValor().equalsIgnoreCase("PROMAX")) {
promax = true;
}
}
public boolean deveExibirSAP() {
return getParametroERP().getValor().equalsIgnoreCase("SAP");
}
public Parametro getParametroERP() {
return parametroERP;
}
public void setParametroERP(Parametro parametroERP) {
this.parametroERP = parametroERP;
}
public ParametroService getParametroService() {
return parametroService;
}
public void setParametroService(ParametroService parametroService) {
this.parametroService = parametroService;
}
public boolean isPromax() {
return promax;
}
public void setPromax(boolean promax) {
this.promax = promax;
}
}
Does anyone have any idea what it might be? Thankful