2013-07-24 2 views
0

내가 내 응용 프로그램JSF : 방법은 없습니다 핵 물질 동안

javax.el.MethodNotFoundException: /test.xhtml @18,99 
action="#{ComplexeController.saveComplexe}": Method not found: 
[email protected]() 

test.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; 
    } 
} 

그리고 지금

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"; 
    }  
} 

내가 그것을 어떻게 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를 해결할 수 있습니까?

+0

action="#{complexeController.saveComplexe}" 

당신은 당신의 페이지를로드 할 수 있습니까? 아니면 버튼을 클릭하면 어떻게됩니까? – danRod

+2

제공된 답변 옆에있는 큰 0 아래의 체크 표시를 클릭하여 질문에 동의하십시오. – Andy

+2

답을 수락하는 것을 잊지 마십시오. 다른 사용자는 대답 한 질문을 읽지 않아야합니다. – erencan

답변

5

보기에 당신은 saveComplexe

action="#{ComplexeController.saveComplexe}" 

ComplexeController 만 SaveComplexe 메소드가 호출합니다. saveComplexe

+1

대답이 도움이된다면 http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – shevchyk

0

이 솔루션에

action="#{ComplexeController.SaveComplexe}" 

또는 ComplexeController 메서드의 이름을 변경하려면

하나의 변화 :
솔루션 test.xhtml 1.
변경 : complexeController.saveComplexe [공지 complexeController의 첫 글자는 소문자입니다.]

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

솔루션 2.
변경 :

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

JSF에 ManagedBeans 구성에 대한 다음 정보를 읽어

@ManagedBean를 사용하는 2 가지 방법이 있습니다 Java Bean 클래스를 Managed Bean 클래스에 공개합니다.

방법 1.

이름은 같지만 첫 글자로 노출 된 콩이 작은 경우, 즉, 당신이 같이 Facelet에서 빈에 액세스 할 수있다이 경우
@ManagedBean 
public class ComplexeController{ 
.... 
} 

#{complexeController} 

웨이 2.

이 경우 동일한 이름이지만 첫 번째 문자가 노출 된 bean은 더 작은 경우입니다.전자., 당신은 낮은 경우 예를 들어, 먼저 문자로 ManagedBean은 액세스 할 수

#{myBean} 
+2

콩이 문제가되지 않습니다. 예외는 콩은 발견되지만 방법은 없다고 말합니다. – BalusC

0

시도로 Facelet에서 빈에 액세스 할 수 있습니다 대신

action="#{ComplexeController.saveComplexe}" 
관련 문제