jsf - jdbc update with dao pattern not working -


i have jsf page update employee table code.... can data,but can't update primefaces.and when debug it,it doesn't anything. need update data. page controller

@managedbean(name = "homebean") @viewscoped public class homecontroller implements serializable {      private employee employee;     private list<employee> employees;     private employeeedao employeeedao;      public homecontroller() {         employeeedao = new employeedaoimpl();     }      public employee getemployee() {         return employee;     }      public void setemployee(employee employee) {         this.employee = employee;     }      public list<employee> getemployees() {          return employees;     }      public void setemployees(list<employee> employees) {         this.employees = employees;     }      public void editemployee() throws sqlexception {         employee e = this.getemployee();         employeeedao.update(e);     }      @postconstruct     private void getlistemployees() {         employees = employeeedao.employees(20, 10);     } } 

and dao

public class employeedaoimpl implements employeeedao, serializable {      private preparedstatement ps;     private resultset rs;      @override     public void add(employee emp) {         try (connection c = connectionhelper.getconnection()) {             string sql = "update employees"                     + "   set first_name = ?,"                     + "       last_name = ?,"                     + "       email = ? employee_id=?";               ps = c.preparestatement(sql);             ps.setstring(1, emp.getfirstname());             ps.setstring(2, emp.getlastname());             ps.setstring(3, emp.getemail());             ps.setint(4, emp.getemployeeid());             ps.executeupdate();             //throw new unsupportedoperationexception("not supported yet."); //to change body of generated methods, choose tools | templates.         } catch (sqlexception ex) {             logger.getlogger(employeedaoimpl.class.getname()).log(level.severe, null, ex);         }     }      @override     public void update(employee emp) throws sqlexception {         try (connection c = connectionhelper.getconnection()) {             string sql = "update employees "                     + "   set first_name = ?,"                     + "       last_name = ?,"                     + "       email = ? employee_id=?";               ps = c.preparestatement(sql);             ps.setstring(1, emp.getfirstname());             ps.setstring(2, emp.getlastname());             ps.setstring(3, emp.getemail());             ps.setint(4, emp.getemployeeid());             ps.execute();         } catch (sqlexception ex) {             logger.getlogger(employeedaoimpl.class.getname()).log(level.severe, null, ex);         }     }      @override     public list<employee> employees(int size, int lastrow) {         list< employee> list = null;         try (connection c = connectionhelper.getconnection()) {             string sql = "select rownum num,emp.* employees emp order rownum";              ps = c.preparestatement(sql);             rs = ps.executequery();             list = new arraylist<employee>();             while (rs.next()) {                 employee e = new employee();                 e.setemployeeid(rs.getint("employee_id"));                 e.setfirstname(rs.getstring("first_name"));                 e.setlastname(rs.getstring("last_name"));                 e.setemail(rs.getstring("email"));                 e.sethiredate(rs.getdate("hire_date"));                 e.setsalary(rs.getbigdecimal("salary"));                 list.add(e);             }         } catch (exception e) {         }         return list;         // throw new unsupportedoperationexception("not supported yet."); //to change body of generated methods, choose tools | templates.     }      @override     public employee getbyid(string id) {          return null;         //  throw new unsupportedoperationexception("not supported yet."); //to change body of generated methods, choose tools | templates.     } } 

and jsf page..

            <p:datatable id="employeetable" value="#{homebean.employees}" var="emp" rows="10" paginator="true"                          selection="#{homebean.employee}">                  <p:column headertext="first name">#{emp.firstname}</p:column>                 <p:column headertext="first name">#{emp.lastname}</p:column>                 <p:column headertext="first name"><h:outputtext value="#{emp.salary}">                         <f:convertnumber type="currency" currencysymbol="$ "/>                     </h:outputtext></p:column>                 <p:column headertext="first name">#{emp.email}</p:column>                 <p:column width="50">                     <p:commandbutton value="edit" oncomplete="editdialog.show();"                                      partialsubmit="true" update="@([id$=display])">                         <f:setpropertyactionlistener value="#{emp}" target="#{homebean.employee}" />                     </p:commandbutton>                 </p:column>             </p:datatable>           </h:form>         <h:form>             <p:dialog widgetvar="editdialog" id="edit" modal="true" appendtobody="true" resizable="false">                  <h:panelgrid id="display" columns="2" cellspacing="4">                     <h:outputtext value="id"/>                     <p:inputtext value="#{homebean.employee.employeeid}" disabled="true">                         <f:convertnumber type="number"/></p:inputtext>                     <p:spacer/><p:spacer/>                     <h:outputtext value="first name"/>                     <h:outputtext value="last name"/>                     <p:inputtext value="#{homebean.employee.firstname}"/>                     <p:inputtext value="#{homebean.employee.lastname}"/>                     <h:outputtext value="email"/>                     <h:outputtext value="salary"/>                     <p:inputtext value="#{homebean.employee.email}"/>                  </h:panelgrid>                 <p:separator/>                 <p:commandbutton value="save" action="#{homebean.editemployee()}" partialsubmit="true"                                  update="@([id$=employeetable])" oncomplete="editdialog.hide();"/>             </p:dialog>          </h:form>     </ui:define> 

finally answer....we need make sure property of employee correct. , have match datatype our database...thanks all


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -