jsf 2 - jsf giving method not found Exception though it is there, javax.el.MethodNotFoundException -


i m getting following exception when trying display h:datatable using backing bean

javax.faces.el.methodnotfoundexception: javax.el.methodnotfoundexception: /table.xhtml @29,36 action="#{user.editemployee}": method not found: com.jason.jsf.user@1df228e.editemployee() javax.faces.component.methodbindingmethodexpressionadapter.invoke(methodbindingmethodexpressionadapter.java:88) com.sun.faces.application.actionlistenerimpl.processaction(actionlistenerimpl.java:98) javax.faces.component.uicommand.broadcast(uicommand.java:311) javax.faces.component.uidata.broadcast(uidata.java:912) javax.faces.component.uiviewroot.broadcastevents(uiviewroot.java:781) javax.faces.component.uiviewroot.processapplication(uiviewroot.java:1246) com.sun.faces.lifecycle.invokeapplicationphase.execute(invokeapplicationphase.java:77) com.sun.faces.lifecycle.phase.dophase(phase.java:97) com.sun.faces.lifecycle.lifecycleimpl.execute(lifecycleimpl.java:114) javax.faces.webapp.facesservlet.service(facesservlet.java:308) org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) 

when executing following code these files new jsf , m learning please explanation

employee.java

 package com.jason.jsf;  import javax.faces.bean.managedbean; import javax.faces.bean.sessionscoped;  @managedbean(name = "employee", eager = true) @sessionscoped public class employee {      private string id, name;     private boolean canedit;      public employee() {         super();         // todo auto-generated constructor stub     }      public employee(string id, string name) {         super();         id = id;         this.name = name;     }      public string getid() {         return id;     }      public void setid(string id) {         id = id;     }      public string getname() {         return name;     }      public void setname(string name) {         this.name = name;     }      public boolean iscanedit() {         return canedit;     }      public void setcanedit(boolean canedit) {         this.canedit = canedit;     }  } 

here user.java

    package com.jason.jsf;  import java.util.arraylist; import java.util.arrays;  import javax.faces.bean.managedbean; import javax.faces.bean.sessionscoped;  @managedbean(name = "user", eager = true) @sessionscoped public class user {      private static final long serialversionuid = 1l;      private string name;     private string id;      private static final arraylist<employee> employees = new arraylist<employee>(             arrays.aslist(new employee("john", "marketing"), new employee(                     "robert", "marketing"), new employee("mark", "sales"),                     new employee("chris", "marketing"), new employee("peter",                             "customer care")));         public arraylist<employee> getemployees() {         return employees;     }       public string addemployee() {      employee employee = new employee(name, id);      employees.add(employee);      return null;      }       public string deleteemployee(employee employee) {      employees.remove(employee);      return null;      }        public string editemployee(employee employee){           employee.setcanedit(true);           return null;        }         public string saveemployees(){           //set "canedit" of employees false            (employee employee : employees){              employee.setcanedit(false);           }                return null;        }      public string getname() {         return name;     }      public void setname(string name) {         this.name = name;     }      /**      * @return id      */     public string getid() {         return id;     }      /**      * @param id      *            id set      */     public void setid(string id) {         this.id = id;     }  } 

here table.xhtml

    <?xml version="1.0" encoding="utf-8"?> <!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:h="http://java.sun.com/jsf/html"     xmlns:f="http://java.sun.com/jsf/core"> <h:head>     <title>jsf tutorial</title>     <h:outputstylesheet library="css" name="style.css" /> </h:head> <h:body>     <h:form>         <h:datatable value="#{user.employees}" var="emp"             styleclass="employeetable" headerclass="employeetableheader"             rowclasses="employeetableoddrow,employeetableevenrow">             <h:column>                 <f:facet name="header">name</f:facet>                 <h:inputtext value="#{emp.name}" size="10" rendered="#{emp.canedit}" />                 <h:outputtext value="#{emp.name}" rendered="#{not emp.canedit}" />             </h:column>             <h:column>                 <f:facet name="header">id</f:facet>                 <h:inputtext value="#{emp.id}" size="20" rendered="#{emp.canedit}" />                 <h:outputtext value="#{emp.id}" rendered="#{not emp.canedit}" />             </h:column>             <h:column>                 <f:facet name="header">edit</f:facet>                 <h:commandbutton value="edit" action="#{user.editemployee}"                     rendered="#{not emp.canedit}">                 </h:commandbutton>             </h:column>         </h:datatable>         <br />         <h:commandbutton value="save employees" action="#{user.saveemployees}" />      </h:form> </h:body> </html> 

i have referred different similar questions didn't answer appropriate problem. please me solution

thanks in advance.

as far can see, editemployee(employee employee) method has parameter of type employee, you're not passing value parameter , that's why tries invoke method same name, no parameters.

since there no such, throws methodnotfoundexception.

and since you're using jsf 2.0+, can pass parameter this:

<h:commandbutton value="edit" action="#{user.editemployee(emp)}"                  rendered="#{not emp.canedit}"> </h:commandbutton> 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -