title: struts2 jquery grid-beginner brief example
body: <p>I want to create a form page having text fields and editable grid table in it where the data entered in the text fields dynamically should be added into the grid table down in the form and we can edit the data in the grid table.I am getting the data I am entering statically is not getting saved in the grid.I am attaching the classes which I have now just suggest me what to do as I am new to struts2.</p>
  
  <p>my jsp page is:</p>
  
  <pre class="lang-jsp prettyprint-override"><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
   pageEncoding="ISO-8859-1"%&gt;
  &lt;%@ taglib prefix="s" uri="/struts-tags" %&gt;
  &lt;%@ taglib prefix="sj" uri="/struts-jquery-tags" %&gt;   
  &lt;%@taglib prefix="sjg" uri="/struts-jquery-grid-tags"%&gt;
  
   &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
   &lt;html&gt;
   &lt;head&gt;
   &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
   &lt;title&gt;Product Master&lt;/title&gt;
   &lt;sj:head jqueryui="true"/&gt;
   &lt;/head&gt;
   &lt;body&gt;
  
   &lt;tr&gt;&lt;a href="javascript:update('&lt;s:property      value="anyValueYouwantToSend"/&gt;')"&gt;Stock&lt;/a&gt;&lt;/tr&gt;
   &lt;tr&gt;&lt;a href="javascript:update('&lt;s:property value="anyValueYouwantToSend"/&gt;')"&gt;Substitutes&lt;/a&gt;&lt;/tr&gt;
  
   &lt;s:form action="Welcome" namespace="/"&gt;
   &lt;s:textfield name="productCode" label="Product Code"&gt;&lt;/s:textfield&gt;
   &lt;s:textfield name="productName" label="Product Name"&gt;&lt;/s:textfield&gt;
   &lt;s:textfield name="packaging" label="Packaging"&gt;&lt;/s:textfield&gt;
   &lt;s:textfield name="conversion" label="Conversion"&gt;&lt;/s:textfield&gt;
   &lt;s:textfield name="rackNumber" label="Rack Number"&gt;&lt;/s:textfield&gt;
   &lt;s:textfield name="manufacturer" label="Manufacturer"&gt;&lt;/s:textfield&gt;
  
   &lt;s:submit name="btnSave" type="submit" value="Add"/&gt;
   &lt;/s:form&gt;
   &lt;s:url var="hello" action="getData" method="post"&gt;&lt;/s:url&gt;
   &lt;sjg:grid id="gridtable"
     caption="Product Master"
     dataType="json"
     href="%{hello}"
     pager="true"
     gridModel="gridModel"
     rowList="10,15,20"
     rowNum="15"
     rownumbers="true"&gt;
  
  &lt;sjg:gridColumn name="productCode" index="productCode" title="ProductCode" sortable="false" value="34545"/&gt;
  &lt;sjg:gridColumn name="productName" index="productName" title="ProductName" sortable="false" value="hgfhgh"/&gt;
  &lt;sjg:gridColumn name="packaging" index="packaging" title="Packaging" sortable="false" value="786878"/&gt;
  &lt;sjg:gridColumn name="conversion" index="conversion" title="Conversion" sortable="false" value="78787"/&gt;
  &lt;sjg:gridColumn name="rackNumber" index="rackNumber" title="RackNumber" sortable="false" value="7898"/&gt;
  &lt;sjg:gridColumn name="manufacturer" index="manufacturer" title="Manufacturer" sortable="false" value="87878"/&gt;
  
  
  &lt;/sjg:grid&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>My Action class:</p>
  
  <pre class="lang-java prettyprint-override"><code>import java.`util.ArrayList`;
  import java.`util.List`;
  import `com.srivasishta.hms.pharmacy.domain.Productmaster`;
  import `com.opensymphony.xwork2.ActionSupport`;
  
  public class `ProductAction`  extends `ActionSupport`{
  
      List&lt;`Productmaster`&gt; list=null;
  
      public List&lt;`Productmaster`&gt; `getList`() {
          return list;
      }
  
      public void `setList(List&lt;`Productmaster&gt; list) {
          this.list = list;
      }
      public String execute()throws Exception
      {
          list=new `ArrayList&lt;Productmaster&gt;`();
          `Productmaster` product=new `Productmaster`();
          `Productinfo` pi=new `Productinfo`();
          `product.setProductCode`(34545);
          `product.setProductName`("hgfhgh");
          `product.setPacks`(786878);
          `product.setQuantityPack`(78787);
          `product.setPurchaseRate`(7898);
          `product.setIpSellingRate`(87878);
          `product.setOpSellingRate`(87878);
          `product.setRowNo`("hgfh");
          `product.setRackNo`("hgfhnbm");
  
          `product.setProductType`("hgfjkl");
          `product.setBatchNo`("hqwed");
          `product.setMrp`("herwt");
          `list.add`(product);
  
          `Productmaster` product1=new `Productmaster`();
          `product.setProductCode`(34545);
          `product.setProductName`("hgfhgh");
          `product.setPacks`(786878);
          `product.setQuantityPack`(78787);
          `product.setPurchaseRate`(7898);
          `product.setIpSellingRate`(87878);
          `product.setOpSellingRate`(87878);
          `product.setRowNo`("hgfh");
          `product.setRackNo`("hgfhnbm");
  
          `product.setProductType`("hgfjkl");
          `product.setBatchNo`("hqwed");
          `product.setMrp`("herwt");
          list.add(product1);
          `pi.setGridModel`(list);
          return "success";
      }
  }
  </code></pre>
  
  <p>My Productinfo.java class is:</p>
  
  <pre class="lang-java prettyprint-override"><code>import `java.util.List`;
  import `com.srivasishta.hms.pharmacy.domain.*`;
  public class `Productinfo` {
      private List&lt;`Productmaster`&gt; `gridModel`;
      // get how many rows we want to have into the grid – rowNum attribute in the
      // grid
      private Integer rows = 0;
      // Get the requested page. By default grid sets this to 1.
      private Integer page = 0;
      // sorting order – asc or desc
      private String sord;
      // get index row – i.e. user click to sort.
      private String `sidx`;
      // Search Field
      private String `searchField`;
      // The Search String
      private String `searchString`;
      // he Search Operation
      // ['eq','ne','lt','le','gt','ge','bw','bn','in','ni','ew','en','cn','nc']
      private String `searchOper;
      // Your Total Pages
      private Integer total = 0;
      // All Record
      private Integer records = 0;
      public void execute() {
          int to = (rows * page);
          //int from = to–rows;
          page = 1;
          rows = `gridModel.size`();
          records = `gridModel.size`();
          // calculate the total pages for the query
          total = records;
      }
      public List&lt;`Productmaster`&gt; `getGridModel`() {
          return `gridModel`;
      }
      public void `setGridModel`(List&lt;`Productmaste`r&gt; `gridModel`) {
          `this.gridModel` = `gridModel`;
          execute();
      }
      public Integer `getRows`() {
          return rows;
      }
      public void `setRows`(Integer rows) {
          this.rows = rows;
      }
      public Integer `getPage`() {
          return page;
      }
      public void `setPage`(Integer page) {
          this.page = page;
      }
      public String `getSord`() {
          return `sord`;
      }
      public void `setSord`(String sord) {
          `this.sord` = sord;
      }
      public String `getSidx`() {
          return sidx;
      }
      public void setSidx(String sidx) {
          `this.sidx` = sidx;
      }
      public String `getSearchField`() {
          return searchField;
      }
      public void `setSearchField`(String searchField) {
          `this.searchField` = searchField;
      }
      public String `getSearchString`() {
          return searchString;
      }
      public void `setSearchString`(String searchString) {
          `this.searchString` = searchString;
      }
      public String getSearchOper() {
          return searchOper;
      }
      public void `setSearchOper`(String searchOper) {
          `this.searchOper` = searchOper;
      }
      public Integer `getTotal`() {
          return total;
      }
      public void `setTotal`(Integer total) {
          this.total = total;
      }
      public Integer `getRecords`() {
          return records;
      }
      public void `setRecords`![enter image description here][1](Integer records) {
          this.records = records;
      }
      // Getters and Setters for Attributes
  }
  </code></pre>