0

I’m facing a strange problem. My page can not find a property that has public acessors (get and set) and is initialized. The error presented is:

javax.el.PropertyNotFoundException: /empresa.xhtml @77,68 value="#{empresaManager.empresaEdit.cdEmp}": Target Unreachable, 'empresaEdit' returned null

public class Empresa implements Serializable {
    private Integer cdEmp;
    private String deEmp;
    private String nmFtsEmp;

    /* getters and setters */
} 


@ManagedBean(name="empresaManager")
@SessionScoped
public class EmpresaManager extends Base4AllActions implements Serializable, Actions4AllButtons {
    private static final long serialVersionUID = 1L;
    private static EmpresaTransaction empresaTransaction;
    private Empresa empresaEdit = new Empresa();
    private List<Empresa> empresas = new ArrayList<>();
    private String deEmpresaFind;
    private String tpPsq;

    private final static String TPPSQ_BYNAME = "NAME";
    private final static String TPPSQ_BYFANTASY = "FANTASY";

    public EmpresaManager() {
        super();
        empresaTransaction = new EmpresaTransaction();
        this.tpPsq = TPPSQ_BYNAME;
        empresaEdit = new Empresa();
        this.setNone();
    }

    public Empresa getEmpresaEdit() {
        return empresaEdit;
    }

    public void setEmpresaEdit(Empresa empresaEdit) {
        this.empresaEdit = empresaEdit;
    }

    /* getters, setters and other methods */
} 


<p:outputLabel value="#{prompt['empresa-cdEmp']}" for="cdEmp" />
<p:inputText id="cdEmp" value="#{empresaManager.empresaEdit.cdEmp}" required="false"
   size="3" maxlength="4" readonly="#{empresaManager.key}" />
<h:message for="cdEmp" styleClass="errors" /> 

I'm using Primefaces Icarus Premium Layout that uses Primefaces 6.0

2 Answers2

0

Place you code in the constructor in a new function annotated by @PostConstruct

Do not use constructor in a managed bean class..

FBRD
  • 63
  • 8
  • Hi Fadi, I changed the code and the problem persists. – OrlandoDias Sep 08 '16 at 11:35
  • `cdEmp` in your class `Empresa` is of type Integer class, you can use `int` as primitive type instead, or create new instance of Integer if it equal null in the getter of this attribute – FBRD Sep 08 '16 at 12:18
  • Hi, Fadi, I changed to int and the messges went to another empresa's property (String deEmp). Must I implement this kind of "singleton" in every property? – OrlandoDias Sep 08 '16 at 14:57
0

I fixed it. 1) I added CDI and WELD as maven dependencies. 2) I changed de view adding a new form tag (h:form). 3) I changed the annotation ManagedBean by Named.

The corrected project can be downloaded in my google drive: