目标无法访问,返回null

时间:2011-09-06 01:10:25

标签: java-ee jsf-2 primefaces

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

  

注意:/infoprojet.xhtml @ 493,159 value =“#{acteurObjetProjetBean.currentActeurObjetProjet.objets.nomObjet}”:目标无法访问,'objets'返回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>

此致

1 个答案:

答案 0 :(得分:11)

  

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

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

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

您也可以在ActeurObjetProjetBean的构造函数中执行此操作。

private ActeurObjetProjet currentActeurObjetProject;

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

选择最适合功能/业务要求的任何内容。

相关问题