title: JSF(1.2) DataTable edit row with button click
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/4533508/make-editable-rows-in-datatable">Make editable rows in Datatable</a>  </p>
  </blockquote>
  
  
  
  <p>Folks,</p>
  
  <p>In the below table I would like to edit the rows.</p>
  
  <p><img src="https://i.stack.imgur.com/GknHv.png" alt="enter image description here"></p>
  
  <p>When I click the edit button, the screen will look like this, editable fields
  <img src="https://i.stack.imgur.com/7VYqY.png" alt="enter image description here"></p>
  
  <p>and when I click save button the list should be updated with the new values for the 
  same row. Say for example, I change the row to 2000, Micky, 4500.</p>
  
  <p>How can I achieve this ?</p>
  
  <p>I tried the below logic, but it is not working, please help me out.</p>
  
  <pre><code>  &lt;h:dataTable binding="#{myBean.dataTable}" id="beanTable" value="#{myBean.dataList}" var="dataItem" styleClass="dataTableEx" headerClass="headerClass"
                  columnClasses="columnClass1" rowClasses="rowClass1,rowClass2" border="1"  cellpadding="2" cellspacing="0" &gt;
  
  &lt;h:column&gt;
      &lt;f:facet name="header"&gt;
          &lt;h:outputText value="Save" /&gt;
      &lt;/f:facet&gt;
      &lt;h:commandButton value="Save" actionListener="#{myBean.saveAction}"  /&gt;     
  &lt;/h:column&gt;
  
  &lt;h:column&gt;
      &lt;f:facet name="header"&gt;
          &lt;h:outputText value="Edit" /&gt;
      &lt;/f:facet&gt;
      &lt;h:commandButton id="edit"  value="Edit" actionListener="#{myBean.editAction}"  /&gt;      
  &lt;/h:column&gt;
  
  
  public void editAction(ActionEvent e){
          MyData data = (MyData)dataTable.getRowData();
          data.setEditable(true);
      }
  
  
  // saveAction is not working.   
      public void saveAction(ActionEvent e){
          int index = dataTable.getRowIndex();
          MyData data = (MyData)dataTable.getRowData(); // returns old value not the newly edited values.
          dataList.remove(index); // dataList has the bean objects
          dataList.add(index, data); 
      }
  </code></pre>