title: How to add clear button into JSF table?
body: <p>I'm working on this JSF table which is used for displaying data.</p>
  
  <p><img src="https://i.stack.imgur.com/AS9zx.png" alt="enter image description here"></p>
  
  <p>When I click the edit button the row in into the JSF page can be edit.</p>
  
  <p><img src="https://i.stack.imgur.com/2G5sK.png" alt="enter image description here"></p>
  
  <p>This is the code:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"   
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        &gt;
      &lt;h:head&gt;
          &lt;h:outputStylesheet library="css" name="table-style.css"  /&gt;
      &lt;/h:head&gt;
      &lt;h:body&gt;
  
          &lt;h:form&gt;
              &lt;h:dataTable value="#{order.orderList}" var="o"
                  styleClass="order-table"
                  headerClass="order-table-header"
                  rowClasses="order-table-odd-row,order-table-even-row"
              &gt;
                          &lt;h:column&gt;
  
                      &lt;f:facet name="header"&gt;Select&lt;/f:facet&gt;
  
                      &lt;h:selectBooleanCheckbox value="#{order.selectedIds[dataItem.id]}" /&gt;
  
                  &lt;/h:column&gt;
                  &lt;h:column&gt;
  
                      &lt;f:facet name="header"&gt;Order No&lt;/f:facet&gt;
  
                      &lt;h:inputText value="#{o.orderNo}" size="10" rendered="#{o.editable}" /&gt;
  
                      &lt;h:outputText value="#{o.orderNo}" rendered="#{not o.editable}" /&gt;
  
                  &lt;/h:column&gt;
  
                  &lt;h:column&gt;
  
                      &lt;f:facet name="header"&gt;Product Name&lt;/f:facet&gt;
  
                      &lt;h:inputText value="#{o.productName}" size="20" rendered="#{o.editable}" /&gt;
  
                      &lt;h:outputText value="#{o.productName}" rendered="#{not o.editable}" /&gt;
  
                  &lt;/h:column&gt;
  
                  &lt;h:column&gt;
  
                      &lt;f:facet name="header"&gt;Price&lt;/f:facet&gt;
  
                      &lt;h:inputText value="#{o.price}" size="10" rendered="#{o.editable}" /&gt;
  
                      &lt;h:outputText value="#{o.price}" rendered="#{not o.editable}" /&gt;
  
                  &lt;/h:column&gt;
  
                  &lt;h:column&gt;
  
                      &lt;f:facet name="header"&gt;Quantity&lt;/f:facet&gt;
  
                      &lt;h:inputText value="#{o.qty}" size="5" rendered="#{o.editable}" /&gt;
  
                      &lt;h:outputText value="#{o.qty}" rendered="#{not o.editable}" /&gt;
  
                  &lt;/h:column&gt;
  
                  &lt;h:column&gt;
  
                      &lt;f:facet name="header"&gt;Action&lt;/f:facet&gt;
  
                      &lt;h:commandLink value="Edit" action="#{order.editAction(o)}" rendered="#{not o.editable}" /&gt;
  
                  &lt;/h:column&gt;
  
              &lt;/h:dataTable&gt;
  
              &lt;h:commandButton value="Save Changes" action="#{order.saveAction}" /&gt;
                  &lt;h:commandButton value="Delete" action="#{order.getSelectedItems}" /&gt;
  
          &lt;/h:form&gt;
      &lt;/h:body&gt;
  
  &lt;/html&gt;
  
  
  import java.io.Serializable;
  import java.math.BigDecimal;
  import java.util.Arrays;
  
  import java.util.HashMap;
  import java.util.Map;
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  import javax.faces.bean.ManagedBean;
  import javax.faces.bean.SessionScoped;
  
  @ManagedBean(name="order")
  @SessionScoped
  public class OrderBean implements Serializable{
  
          private Map&lt;Long, Boolean&gt; selectedIds = new HashMap&lt;Long, Boolean&gt;();
          private List&lt;OrderBean&gt; selectedDataList;
          Iterable&lt;OrderBean&gt; dataList = null;
  
          public String getSelectedItems() {
  
              // Get selected items.
              selectedDataList = new ArrayList&lt;OrderBean&gt;();
  
              for (OrderBean dataItem : dataList) {
                  if (selectedIds.get(dataItem.getId()).booleanValue()) {
                      selectedDataList.add(dataItem);
                      selectedIds.remove(dataItem.getId()); // Reset.
                      /* Insert into DB SQL stetement which deletes rows by using 
                         dataItem as key */
                  }
              }
  
              return "selected"; // Navigation case.
          }
  
          public Map&lt;Long, Boolean&gt; getSelectedIds() {
              return selectedIds;
          }
  
          public List&lt;OrderBean&gt; getSelectedDataList() {
              return selectedDataList;
          }
  
  
          /* Create list with data */
  
  
      private static final long serialVersionUID = 1L;
  
      private static final ArrayList&lt;Order&gt; orderList = 
          new ArrayList&lt;Order&gt;(Arrays.asList(
  
          new Order("A0001", "Intel CPU", 
                  new BigDecimal("700.00"), 1),
          new Order("A0002", "Harddisk 10TB", 
                  new BigDecimal("500.00"), 2),
          new Order("A0003", "Dell Laptop", 
                  new BigDecimal("11600.00"), 8),
          new Order("A0004", "Samsung LCD", 
                  new BigDecimal("5200.00"), 3),
          new Order("A0005", "A4Tech Mouse", 
                  new BigDecimal("100.00"), 10)
      ));
  
      public ArrayList&lt;Order&gt; getOrderList() {
  
          return orderList;
  
      }
  
      public String saveAction() {
  
          //get all existing value but set "editable" to false 
          for (Order order : orderList){
              order.setEditable(false);
          }
  
          //return to current page
          return null;
  
      }
  
      public String editAction(Order order) {
  
          order.setEditable(true);
          return null;
      }
  
      private Object getId() {
          throw new UnsupportedOperationException("Not yet implemented");
      }
  
      public static class Order{
  
          String orderNo;
          String productName;
          BigDecimal price;
          int qty;
          boolean editable;
  
          public Order(String orderNo, String productName, BigDecimal price, int qty) {
              this.orderNo = orderNo;
              this.productName = productName;
              this.price = price;
              this.qty = qty;
          }
  
          public boolean isEditable() {
              return editable;
          }
          public void setEditable(boolean editable) {
              this.editable = editable;
          }
          public String getOrderNo() {
              return orderNo;
          }
          public void setOrderNo(String orderNo) {
              this.orderNo = orderNo;
          }
          public String getProductName() {
              return productName;
          }
          public void setProductName(String productName) {
              this.productName = productName;
          }
          public BigDecimal getPrice() {
              return price;
          }
          public void setPrice(BigDecimal price) {
              this.price = price;
          }
          public int getQty() {
              return qty;
          }
          public void setQty(int qty) {
              this.qty = qty;
          }
      }
  }
  </code></pre>
  
  <p>I want to add cancel button which is displayed after the edit button in pushed. Now if I want to cancel to edit the table I have to reload the page.
  How I can add this button? </p>