【问题标题】:Jsf page cannot call bean's methodjsf页面不能调用bean的方法
【发布时间】:2012-12-28 20:47:00
【问题描述】:

我有一个非常简单的页面,这让我发疯了。 基本上我在一个bean上有2个按钮调用方法,但每次我得到它都不会调用它们:

javax.el.MethodNotFoundException:/vues/vehicule/creationVehicule.xhtml @49,94 action="#{creationVehicule.creer}":找不到方法:fr.efrei.gpa.web.beans.vehicule.ModificationVehiculeBean@ 1387498.creer()

这是我的控制器(我删除了导入)

@Getter
@Setter
@ManagedBean(name = "creationVehicule")
@ViewScoped
public class CreationVehiculeBean implements Serializable{
    //
    private static final long serialVersionUID = 4790600937909196533L;
    private String immatriculation;
    private Date dateAchat;
    private String marque;
    private String modele;
    private String kilometrage;
    private String puissance;
    private String etat;

    private VehiculeService vehiculeService = new VehiculeDelegate();

    public void creer() throws Exception{
        Vehicule v = new Vehicule();
        v.setImmatriculation(immatriculation);
        v.setKilometrage(kilometrage);
        v.setMarque(marque);
        v.setModele(modele);
        v.setPuissance(puissance);
        v.setEtat("etat");
        v.setDateAchat(dateAchat);
        int id = vehiculeService.create(v);

        FacesContext.getCurrentInstance().getExternalContext().redirect("/web-office/vue/vehicule/rechercherContrat.xhtml&id="+Integer.toString(id));
    }

    public String annuler(){
        return "/vues/vehicule/rechercheVehicule?faces-redirect=true";
    }

}

这是我的观点

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:cogepat="http://cogepat.com/facelets"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:ccc="http://java.sun.com/jsf/composite/compositeForms"
    xmlns:cccg="http://java.sun.com/jsf/composite/compositeGeneral">

<ui:composition template="/templates/template.xhtml">
    <ui:param name="module" value="vehicules" />
    <ui:define name="title">
        #{msg.CreerUnProduit}
    </ui:define>

    <ui:define name="titreModule">
        #{msg.GestionVehicule}
    </ui:define>

    <ui:define name="onglets">
        <ul>
            <li>
                <a class="tab" href="#{facesContext.externalContext.requestContextPath}/vues/vehicule/rechercheVehicule.xhtml">#{msg.RechercherUnVehicule}</a>
            </li>
            <li>
                <a class="selectedTab" href="#{facesContext.externalContext.requestContextPath}/vues/vehicule/creationVehicule.xhtml">#{msg.CreerUnVehicule}</a>
            </li>
        </ul>
    </ui:define>

    <ui:define name="nav">
        <h:form>
            <h:commandLink id="link1" value="#{msg.vehicules}" action="rechercheVehicule.xhtml" />
                >#{msg.creation}
        </h:form>
    </ui:define>


    <ui:define name="titreOnglet">
        #{msg.FormCreationVehicule}
    </ui:define>

    <ui:define name="corpsContenu">
        <ccc:formVehicule bean="#{creationVehicule}" />
        <div class="boutons">
                <h:commandButton type="submit" value="#{msg.creer}" action="#{creationVehicule.creer}" />
                <h:commandButton type="submit" value="#{msg.annuler}" action="#{creationVehicule.annuler}" />
        </div>
        <br/><br/>
    </ui:define>

</ui:composition>
</html>

所以当我点击其中任何一个按钮时,我都会收到错误消息。 这很奇怪,因为我以 excat 相同的方式从其他页面调用其他 bean 中的方法。

有什么想法吗? 谢谢。

我使用的是 JDK 6u35, Richfaces 4.2.1.Final, 雄猫 7, 和 JSF 2.1.6

【问题讨论】:

    标签: jsf-2 el managed-bean


    【解决方案1】:

    再次查看异常消息,然后特别查看类名:

    fr.efrei.gpa.web.beans.vehicule.ModificationVehiculeBean@1387498.creer()
    

    这不是您手头的 CreationVehiculeBean 类的 FQN。这表明您有另一个托管 bean 类 ModificationVehiculeBean,它使用完全相同的托管 bean 名称并在类加载中具有优先级和/或在托管 bean 注册中是最后一个。

    ModificationVehiculeBean 类一个不同的托管 bean 名称应该可以解决这个问题。

    【讨论】:

    • 天哪,copyNpaste 错误。你是神。但在我的辩护中,自从我开始以来已经 13 小时了:p。非常感谢 =D。
    猜你喜欢
    • 2012-01-27
    • 2016-02-17
    • 2023-03-27
    • 1970-01-01
    • 2012-11-11
    • 2014-12-30
    • 2012-08-03
    • 2011-09-29
    • 2023-04-07
    相关资源
    最近更新 更多