我面临一个奇怪的问题。我的页面找不到具有公共访问(获取和设置)并初始化的属性。提出的错误是:
javax.el.PropertyNotFoundException:/empresa.xhtml @ 77,68 value =“#{empresaManager.empresaEdit.cdEmp}”:目标无法访问,'empresaEdit'返回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" />
我正在使用使用Primefaces 6.0的Primefaces Icarus Premium Layout
答案 0 :(得分:0)
将代码放在构造函数中由@PostConstruct
不要在托管bean类中使用构造函数。
答案 1 :(得分:0)
我修好了。 1)我添加了CDI和WELD作为maven依赖项。 2)我改变了视图添加新的表单标签(h:表单)。 3)我通过Named更改了注释ManagedBean。