1

开发应用程序时出现此错误

javax.el.MethodNotFoundException: /test.xhtml @18,99 
action="#{ComplexeController.saveComplexe}": Method not found:
fr.code.parc.controller.ComplexeController@97aead.saveComplexe()

测试.xhtml:

<h:body>
<h1>Génération des Complexes</h1>
<h:form>
    Nom Complexe: <h:inputText value="#{ComplexeController.complexe.nomComp}"/><br/>
    Nom Zone: <h:selectOneMenu id="nomZone" value="#{ComplexeController.complexe.zoneParc}" converter="#{GenericConverter}">
        <f:selectItems value="#{ZoneController.remplireItem()}"/>
</h:selectOneMenu>
<br/>
<h:commandButton action="#{ComplexeController.saveComplexe}" value="Insérer un nouveau complexe"/>
<h:commandButton action="#{ComplexeController.updateComplexe}" value="Modifier un complexe"/>
<br/>
<h:commandLink action="complexe" value="acceuil"/>
</h:form>
</h:body>

实体Complexe.java

import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * Complexe generated by hbm2java
 */
@Entity
@Table(name="COMPLEXE"
    ,schema="PROJET"
)
public class Complexe  implements java.io.Serializable {


     private String nomComp;
     private ZoneParc zoneParc;
     private Set<Parc> parcs = new HashSet<Parc>(0);

    public Complexe() {
    }


    public Complexe(String nomComp) {
        this.nomComp = nomComp;
    }
    public Complexe(String nomComp, ZoneParc zoneParc, Set<Parc> parcs) {
       this.nomComp = nomComp;
       this.zoneParc = zoneParc;
       this.parcs = parcs;
    }

     @Id 

    @Column(name="NOM_COMP", unique=true, nullable=false, length=30)
    public String getNomComp() {
        return this.nomComp;
    }

    public void setNomComp(String nomComp) {
        this.nomComp = nomComp;
    }
@ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="NOM_ZONEE")
    public ZoneParc getZoneParc() {
        return this.zoneParc;
    }

    public void setZoneParc(ZoneParc zoneParc) {
        this.zoneParc = zoneParc;
    }
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="complexe")
    public Set<Parc> getParcs() {
        return this.parcs;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (nomComp != null ? nomComp.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Complexe)) {
            return false;
        }
        Complexe other = (Complexe) object;
        if ((this.nomComp == null && other.nomComp != null) || (this.nomComp != null && !this.nomComp.equals(other.nomComp))) {
            return false;
        }
        return true;
    }

    public void setParcs(Set<Parc> parcs) {
        this.parcs = parcs;
    }
}

现在是ComplexeDaoImpl.java

    import config.HibernateUtil;
    import fr.code.parc.model.Complexe;
    import java.util.List;
    import org.hibernate.Session;
    import org.hibernate.Transaction;

    /**
     *
     * @author raddaouirami
     */
    public class ComplexeDaoImpl implements ComplexeDao{

        @Override
        public List<Complexe> list() {
            Session session = HibernateUtil.getSessionFactory().openSession();
            Transaction t = session.beginTransaction();
            List complexes = session.createQuery("from Complexe").list();
            t.commit();
            return complexes;
        }

        @Override
        public Complexe getComplexe(String nomComp) {
            Session session = HibernateUtil.getSessionFactory().openSession();
            return (Complexe) session.load(Complexe.class, nomComp);
        }

        @Override
        public void save(Complexe complexe) {
            Session session = HibernateUtil.getSessionFactory().openSession();
            Transaction t = session.beginTransaction();
            session.save(complexe);
            t.commit();
        }

        @Override
        public void update(Complexe complexe) {
            Session session = HibernateUtil.getSessionFactory().openSession();
            Transaction t = session.beginTransaction();
            session.update(complexe);
            t.commit();
        }

        @Override
        public void remove(Complexe complexe) {
            Session session = HibernateUtil.getSessionFactory().openSession();
            Transaction t = session.beginTransaction();
            session.delete(complexe);
            t.commit();
        }


    }

最后是 ComplexeController.java

import fr.code.parc.dao.ComplexeDao;
import fr.code.parc.dao.ComplexeDaoImpl;
import fr.code.parc.model.Complexe;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;

/**
 *
 * @author raddaouirami
 */

@ManagedBean
@SessionScoped
public class ComplexeController {

    private Complexe complexe;
    private DataModel listeComplexes;
    private int selectedItemIndex;


    /**
     * Creates a new instance of ComplexeController
     */
    public ComplexeController() {
        complexe = new Complexe();
    }
    /* public Complexe getSelected() {
        if (complexe == null) {
            complexe = new Complexe();
            selectedItemIndex = -1;
        }
        return complexe;
    }*/

    public DataModel getListeComplexes() {
        List<Complexe> liste = new ComplexeDaoImpl().list();
        listeComplexes = new ListDataModel(liste);
        return listeComplexes;
}

    /**
     * @return the complexe
     */
    public Complexe getComplexe() {
        return complexe;
    }

    /**
     * @param complexe the complexe to set
     */
    public void setComplexe(Complexe complexe) {
        this.complexe = complexe;
    }


    public String preparationAddComplexe(){
        setComplexe(new Complexe());
        return "test";
}
    public String preparationEditComplexe(){
        setComplexe((Complexe)(getListeComplexes().getRowData()));
        return "test";
}

    public String DeleteComplexe(){
        Complexe complexes = (Complexe)(getListeComplexes().getRowData());
        ComplexeDao dao = new ComplexeDaoImpl();
        dao.remove(complexes);
        return "complexe";
    }
    public String SaveComplexe(){
        ComplexeDao dao = new ComplexeDaoImpl();
        dao.save(getComplexe());
        return "complexe";
    }
    public String UpdateComplexe(){
        ComplexeDao dao = new ComplexeDaoImpl();
        dao.update(complexe);
        return "complexe";
    }    
}

我该如何解决?

4

3 回答 3

5

鉴于您调用saveComplexe

action="#{ComplexeController.saveComplexe}"

ComplexeController 只有SaveComplexe方法。

要么更改为

action="#{ComplexeController.SaveComplexe}"

或将 ComplexeController 中的方法重命名为saveComplexe

于 2013-07-24T22:08:56.190 回答
0

尝试使用第一个字符为小写的方式访问 ManagedBean,例如

action="#{complexeController.saveComplexe}"

代替

action="#{ComplexeController.saveComplexe}"
于 2013-12-04T14:16:55.320 回答
0

2 解决方案:
解决方案 1.
test.xhtml 中的更改:complexeController.saveComplexe [注意 complexeController 中的第一个字母小写]

<h:commandButton action="#{complexeController.saveComplexe}" value="Insérer un nouveau complexe"/>
<h:commandButton action="#{complexeController.updateComplexe}" value="Modifier un complexe"/>

解决方案 2.
ComplexeController.java 中的更改:

@ManagedBean(name="ComplexeController ")
@SessionScoped
public class ComplexeController {
....
}

阅读以下有关在 JSF 中配置 ManagedBeans 的信息:

有两种方法可以使用@ManagedBean将 Java Bean 类公开给 Managed Bean 类。

方式1。

@ManagedBean
public class ComplexeController{
....
}

在这种情况下,bean 以相同的名称公开,但第一个字母小写,即,您可以在 Facelet 中访问 bean

#{complexeController}

方式2。

@ManagedBean(name="myBean")
public class ComplexeController{
....
}

在这种情况下,bean 以相同的名称公开,但第一个字母小写,即,您可以在 Facelet 中访问 bean

#{myBean}
于 2013-07-25T08:32:23.570 回答