java - JSF : able to do mass update but unable to update a single row in a datatable -


i have simple data object: car. showing properties of car objects in jsf datatable. if display properties using inputtext tags, able modified values in managed bean. want single row editable. have placed edit button in separate column , inputtext , outputtext every property of car. edit button toggles rendering of inputtext , outputtext. plus placed update button in separate column used save updated values. on clicking update button, still old values instead of modified values. here complete code:

public class car {      int id;     string brand;     string color;      public car(int id, string brand, string color) {         this.id = id;         this.brand = brand;         this.color = color;     }      //getters , setters of id, brand, color } 

here managed bean:

import java.util.arraylist; import java.util.list; import javax.faces.bean.managedbean; import javax.faces.bean.requestscoped; import javax.faces.component.uidata;  @managedbean(name = "cartree") @requestscoped public class cartree {      int editablerowid;     list<car> carlist;     private uidata mytable;      public cartree() {          carlist = new arraylist<car>();         carlist.add(new car(1, "jaguar", "grey"));         carlist.add(new car(2, "ferari", "red"));         carlist.add(new car(3, "camri", "steel"));     }      public string update() {          system.out.println("updating...");         //below statments print old values, expecting modified values         system.out.println("new car brand is:" + ((car) mytable.getrowdata()).brand);         system.out.println("new car color is:" + ((car) mytable.getrowdata()).color);           //how modified row values in method??          return null;     }      public int geteditablerowid() {         return editablerowid;     }      public void seteditablerowid(int editablerowid) {         this.editablerowid = editablerowid;     }      public uidata getmytable() {         return mytable;      }      public void setmytable(uidata mytable) {         this.mytable = mytable;     }      public list<car> getcars() {         return carlist;     }      public void setcars(list<car> carlist) {         this.carlist = carlist;     } } 

here jsf 2 page:

<?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>facelet title</title>     </h:head>     <h:body>          <h:form id="carform" prependid="false">             <h:datatable id="dt" binding="#{cartree.mytable}" value="#{cartree.cars}" var="car" >                 <h:column>                     <h:outputtext value="#{car.id}" />                 </h:column>                  <h:column>                     <h:outputtext value="#{car.brand}" rendered="#{cartree.editablerowid != car.id}"/>                     <h:inputtext value="#{car.brand}" rendered="#{cartree.editablerowid == car.id}"/>                 </h:column>                  <h:column>                     <h:outputtext value="#{car.color}" rendered="#{cartree.editablerowid != car.id}"/>                     <h:inputtext value="#{car.color}" rendered="#{cartree.editablerowid == car.id}"/>                 </h:column>                  <h:column>                     <h:commandbutton value="edit">                         <f:setpropertyactionlistener target="#{cartree.editablerowid}" value="#{car.id}" />                     </h:commandbutton>                 </h:column>                  <h:column>                     <h:commandbutton value="update" action="#{cartree.update}"/>                 </h:column>              </h:datatable>         </h:form>     </h:body> </html> 

however if keep inputtext tags , remove rendered attributes, modified values in update method. how can modified values single row edit?

i modified values in update method when change scope request session. there better approach instead of using sessionscoped? sessionscoped == server memory,that's why want avoid it.

rant(or frustration?): if there similar objectdatasource of asp.net, have been easier. moderate work datatable, have lookup lifecycle issues. whereas in asp.net objectdatasource + listview combo enough of data + ui related matters plus hardly have lookup lifecycle of control(infact, asp.net guys hardly ever lookup docs). why cant base jsf specification provide control capable of crud operations out of box perhaps lazy loading capability. isn't required each , every application?


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -