【问题标题】:Target Unreachable, returned null [duplicate]目标无法到达,返回 null [重复]
【发布时间】:2011-11-10 23:00:48
【问题描述】:

我在尝试使用对象 currentActeurObjetProjet 并使用 Primefaces 在对话框上显示其属性时遇到问题,但它一直显示此错误:

注意:/infoprojet.xhtml @493,159 value="#{acteurObjetProjetBean.currentActeurObjetProjet.objets.nomObjet}":目标无法到达,“对象”返回 null javax.el.PropertyNotFoundException: /infoprojet.xhtml @493,159 value="#{acteurObjetProjetBean.currentActeurObjetProjet.objets.nomObjet}": 目标无法到达,'objets' 返回 null

这是备份 bean:

package com.mycompany.projet;
.......

/**
 *
 * @author Omar
 */
@Component("etatsBean")
@Scope("session")
public class ActeurObjetProjetBean implements Serializable{
   .......
    private ActeurObjetProjet currentActeurObjetProjet=new ActeurObjetProjet();
   .......
     ////////////////////////////////////////////////////////// Méthodes & fonctions\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

      ////////////////////////////////////////////////////////// setters & getters \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 
    public void setCurrentActeurObjetProjet(ActeurObjetProjet currentActeurObjetProjet)
    {
        this.currentActeurObjetProjet=currentActeurObjetProjet;
    }
    public ActeurObjetProjet getCurrentActeurObjetProjet()
    {
        return currentActeurObjetProjet;
    } 
    .......
} 

这是我的页面代码:

<p:dialog header="Editer Objet" widgetVar="editobjetDialog" resizable="true" width="300" height="300" showEffect="clip" hideEffect="clip" modal="true">
                                    <p:outputPanel id="editobjetDetail" style="text-align:center;" layout="block">
                                        <center>
                                            <h:panelGrid  columns="2" cellpadding="5">
                                                 <h:outputLabel  value="Nom Objet        "/>
                                                 <p:inputText value="#{acteurObjetProjetBean.currentActeurObjetProjet.objets.nomObjet}" style="width: 180px"/>
                                                                                                         <h:outputLabel  value="Accès DB2        "/>
                                                 <p:inputText value="#{acteurObjetProjetBean.currentActeurObjetProjet.objets.accesDb2}" style="width: 180px"/>
                                                 <h:outputLabel  value="Etat        "/>
                                                 <p:inputText value="#{acteurObjetProjetBean.currentActeurObjetProjet.objets.etatObjet}" style="width: 180px"/>
                                                 <h:outputLabel  value="Version        "/>
                                                 <p:inputText value="#{acteurObjetProjetBean.currentActeurObjetProjet.objets.versionObjet}" style="width: 180px"/>

                                            </h:panelGrid>
                                        </center>
                                    </p:outputPanel>
                                </p:dialog>

问候

【问题讨论】:

  • 可能是您缺少一些 getter/setter 或您的对象(属性)未正确初始化。您确定objets 已正确初始化并且在ActeurObjetProjet 中有getter/setter。

标签: jakarta-ee jsf-2 primefaces


【解决方案1】:

javax.el.PropertyNotFoundException: /infoprojet.xhtml @493,159 value="#{acteurObjetProjetBean.currentActeurObjetProjet.objets.nomObjet}": 目标无法到达,'objets' 返回 null

EL 试图告诉您它无法设置nomObjet 值,因为objetsnull。 EL 不会为您自动创建任何嵌套对象属性。它只会自动填充叶子属性。您只需确保currentActeurObjetProject 类的objet 属性不是null。您可以通过在 ActeurObjetProjet 类的构造函数中准备它来做到这一点。

public ActeurObjetProjet() {
    this.objet = new Objet();
}

您也可以在 ActeurObjetProjetBean 的构造函数中这样做。

private ActeurObjetProjet currentActeurObjetProject;

public ActeurObjetProjetBean() {
    this.currentActeurObjetProject = new ActeurObjetProjet();
    this.currentActeurObjetProject.setObject(new Object());
}

选择最适合功能/业务要求的。

【讨论】:

    猜你喜欢
    • 2011-04-14
    • 1970-01-01
    • 2014-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-14
    • 2016-05-28
    相关资源
    最近更新 更多