Heetola
Heetola

Reputation: 6181

Jsf page cannot call bean's method

I have this very simple page wich is driving me crazy. basically I have 2 buttons calling method on a bean, but it won't call them, each time I get :

javax.el.MethodNotFoundException: /vues/vehicule/creationVehicule.xhtml @49,94 action="#{creationVehicule.creer}": Method not found: fr.efrei.gpa.web.beans.vehicule.ModificationVehiculeBean@1387498.creer()

this is my controller (I removed the imports)

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

}

And this is my view

<!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>

so when I clic on either one of those buttons I get the error. which is weird because I'm calling method in other bean from other page in the excat same way.

the buttons

Any ideas? thanks.

I'm using the JDK 6u35, richfaces 4.2.1.Final, tomcat 7, and JSF 2.1.6

Upvotes: 0

Views: 1572

Answers (1)

BalusC
BalusC

Reputation: 1108567

Look once again at the exception message and then particularly at the class name:

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

That's not the FQN of the CreationVehiculeBean class which you're having at hands. This suggests that you've another managed bean class ModificationVehiculeBean which uses exactly the same managed bean name and got precedence in classloading and/or was the last one in managed bean registration.

Giving the ModificationVehiculeBean class a different managed bean name should fix this problem.

Upvotes: 1

Related Questions