title: How to use struts2 grid with form submission
body: <p>I've already searched on Stackoverflow with no luck;</p>
  
  <p>I want to make one filter form in which user enters data and according to that data, I want to show results in Struts2 jQGrid.</p>
  
  <p>By default when page loads, Struts2 jQGrid already have action url having all data.</p>
  
  <p>I tried setting target of form and <code>&lt;sj:a&gt;</code>, but it didnt work.</p>
  
  <p>See code:</p>
  
  <p>This is my Grid:</p>
  
  <pre><code>    &lt;sjg:grid gridModel="items"
                              href="%{itemsUrl}"
                              caption="Items"
                              id="filterGrid"
                              dataType="json"
                              rownumbers="true"
                              pager="true"
                              navigator="false"
                              rowList="10, 15, 20"
                              rowNum="10"
                              viewrecords="true"
                              loadonce="true"
                              formIds="filterForm"
  
                              &gt;
      &lt;sjg:gridColumn name="item.itemname" title="Item Name"&gt;&lt;/sjg:gridColumn&gt;
      &lt;sjg:gridColumn name="shelves.shelfname" title="Shelf Name"&gt;&lt;/sjg:gridColumn&gt;
      &lt;sjg:gridColumn name="quantity" title="Available Qauntity"&gt;&lt;/sjg:gridColumn&gt;
      &lt;sjg:gridColumn name="item.itemprice" title="Item Price"&gt;&lt;/sjg:gridColumn&gt;
  &lt;/sjg:grid&gt;
  </code></pre>
  
  <p>My Form:</p>
  
  <pre><code>&lt;s:form id="filterForm" action="%{filterUrl}"&gt;
      &lt;table style="width:100%"&gt;
          &lt;tr&gt;
              &lt;td colspan="4"&gt;
                  &lt;s:textfield key="global.item.list.name" name="nameContains" /&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td colspan="2"&gt;
                  &lt;s:textfield key="global.item.list.pricefrom" name="priceFrom" /&gt;
              &lt;/td&gt;
              &lt;td colspan="2"&gt;
                  &lt;s:textfield key="global.item.list.priceto" name="priceTo" /&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td colspan="4"&gt;
                  &lt;s:select cssStyle="width: 100%" id="SelectCategoryList"
                      multiple="true" list="categoryList" listKey="categoryId" listValue="categoryType"
                      headerKey="-1" headerValue="Select Type" key="global.add.item.type"
                      loadingText="Item Types Loading..." /&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td colspan="4"&gt;
                  &lt;div id="fields"&gt;&lt;/div&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td colspan="4"&gt;
                  &lt;sj:a targets="filterGrid" button="true"
                      key="global.item.list.form.submit" onClickTopics="reloadMyGrid" /&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  &lt;/s:form&gt;
  </code></pre>
  
  <p>and ajax reloadTopics function:</p>
  
  <pre><code>$.subscribe("reloadMyGrid", function() {
          //alert("df")
          $("#filterForm").submit();
          $("#filterGrid").trigger("reloadGrid");
          return false;
          });
  </code></pre>
  
  <p>Actually I have seen such style in another stackoverflow question (<a href="https://stackoverflow.com/questions/9915211/how-to-load-json-result-on-grid-after-struts2-form-submission?rq=1">here</a>) and i dont know what to write in above function.</p>
  
  <p>Thank You</p>
  
  <p><strong>EDIT #1</strong></p>
  
  <hr>
  
  <p>I ve modified the code as: </p>
  
  <pre><code>&lt;sj:a targets="filterGrid" 
        button="true" 
        key="global.item.list.form.submit" 
        formIds="filterForm" 
        onSuccess‌​Topics="reloadGrid" /&gt; 
  
  &lt;sjg:grid gridModel="items" 
            href="%{itemsUrl}" 
            caption="Items" 
            id="filterGrid" 
            dataType="j‌​son" 
            rownumbers="true" 
            pager="true" 
            navigator="false" 
            rowList‌​="10, 15, 20" 
            rowNum="10" 
            viewrecords="true"&gt; 
  </code></pre>
  
  <p>The form gets submitted,json data also received,but grid not showing anything,even by reloading</p>
  
  <p><strong>EDIT #2</strong></p>
  
  <p>After modifying my complete code is:</p>
  
  <pre><code>&lt;s:url id="filterUrl" action="ListItemFilter" /&gt;
                  &lt;s:form id="filterForm" action="%{filterUrl}"&gt;
                      &lt;table style="width:100%"&gt;
                          &lt;tr&gt; 
                              &lt;td colspan="4"&gt;
                                  &lt;s:textfield key="global.item.list.name" name="nameContains" /&gt;
                              &lt;/td&gt;
                          &lt;/tr&gt;
                          &lt;tr&gt;
                              &lt;td colspan="2"&gt; &lt;s:textfield key="global.item.list.pricefrom" name="priceFrom" /&gt; &lt;/td&gt;
                              &lt;td colspan="2"&gt; &lt;s:textfield key="global.item.list.priceto" name="priceTo" /&gt; &lt;/td&gt;
                          &lt;/tr&gt;
                          &lt;tr&gt;
                              &lt;td colspan="4"&gt;
                                  &lt;s:select
                                      cssStyle="width: 100%"
  
                                      id="SelectCategoryList"
                                      multiple="true"
                                      list = "categoryList" 
                                      listKey = "categoryId" 
                                      listValue = "categoryType" 
                                      headerKey="-1"
                                      headerValue="Select Type"
                                      key = "global.add.item.type" 
                                      loadingText="Item Types Loading..."
                                  /&gt;
                              &lt;/td&gt;
                          &lt;/tr&gt;
                          &lt;tr&gt;
                              &lt;td colspan="4"&gt; 
                                  &lt;div id="fields"&gt;&lt;/div&gt;
                              &lt;/td&gt;
                          &lt;/tr&gt;
                          &lt;tr&gt;
                              &lt;td colspan="4"&gt; &lt;sj:a targets="filterGrid" 
                              button="true" 
                              key="global.item.list.form.submit"
                              formIds="filterForm"
                              onSuccessTopics="reloadGrid"
                               /&gt;
                          &lt;/tr&gt;
                      &lt;/table&gt;
                  &lt;/s:form&gt;
  
  &lt;s:url id="itemsUrl" action="ListItems" /&gt;      
          &lt;div  class="gridSection"&gt;
          &lt;sjg:grid gridModel="items"
                          href="%{itemsUrl}"
                          caption="Items"
                          id="filterGrid"
                          dataType="json"
                          rownumbers="true"
                          pager="true"
                          navigator="false"
                          rowList="10, 15, 20"
                          rowNum="10"
                          viewrecords="true"                      
                          &gt;
                  &lt;sjg:gridColumn name="item.itemname" title="Item Name"&gt;&lt;/sjg:gridColumn&gt;
                  &lt;sjg:gridColumn name="shelves.shelfname" title="Shelf Name"&gt;&lt;/sjg:gridColumn&gt;
                  &lt;sjg:gridColumn name="quantity" title="Available Qauntity"&gt;&lt;/sjg:gridColumn&gt;
                  &lt;sjg:gridColumn name="item.itemprice" title="Item Price"&gt;&lt;/sjg:gridColumn&gt;
               &lt;/sjg:grid&gt;
          &lt;/div&gt;
  </code></pre>
  
  <p>struts.xml:</p>
  
  <pre><code>&lt;action name="ListItems" class="com.acty.libsys.actions.ListItemsAction"&gt;
  &lt;result name="success" type="json"&gt;&lt;/result&gt;
  &lt;/action&gt;
  &lt;action name="ListItemFilter" class="com.acty.libsys.actions.ListItemsAction" method="filter"&gt;
      &lt;result name="success" type="json"&gt;&lt;/result&gt;
  &lt;/action&gt;
  </code></pre>
  
  <p>and the action:</p>
  
  <pre><code>public class ListItemsAction extends ActionSupport {
      private static final long serialVersionUID = 1L;
  
      private List&lt;ItemCategory&gt; categoryList;
  
      public List&lt;ItemCategory&gt; getCategoryList() {
          return categoryList;
      }
  
      public void setCategoryList(List&lt;ItemCategory&gt; categoryList) {
          this.categoryList = categoryList;
      }
  
      public String execute() {
          serviceProvider.openConnection();
          /*This will be available to select box of ListItem.jsp*/
          categoryList = serviceProvider.getItemCategoryMapper().selectByExample(null);
          items = serviceProvider.getShelfItemsMapper().selectItemsFromShelf();System.out.println("fidddds "+items);
          serviceProvider.closeConnection();
          return SUCCESS;
      }
  
      public String filter() {
          ShelfItemsExample example = new ShelfItemsExample();
  
          if(!("".equals(nameContains)))
              example.createCriteria().andItemnameIsLike(nameContains);
          if(priceFrom != null &amp;&amp; priceTo != null)
              example.createCriteria().andItemPriceBetween(priceFrom, priceTo);
  
          System.out.println("nameContains "+nameContains + " priceFrom " + priceFrom);
          if(itemCategoryFields != null &amp;&amp; !(itemCategoryFields.isEmpty())) {
              List&lt;String&gt; fieldIds = new ArrayList&lt;String&gt;();
              List&lt;String&gt; fieldValues = new ArrayList&lt;String&gt;();
  
              for(Map.Entry&lt;String, String&gt; entry: itemCategoryFields.entrySet()){
                  fieldIds.add(entry.getKey());
                  fieldValues.add(entry.getValue());
              }
              example.createCriteria().andFieldIdIn(fieldIds);
  
              example.setCondition(fieldValues);
          }       
  
          serviceProvider.openConnection();
          items = serviceProvider.getShelfItemsMapper().selectFiltered(example);
          System.out.println("fids "+items);
          serviceProvider.closeConnection();
          return SUCCESS;
      }
  
      public void setItems(List&lt;ShelfItems&gt; items) {
          this.items = items;
      }
  
      /* Used when filter button clicked*/
      private String nameContains;
      private BigDecimal priceFrom;
      private BigDecimal priceTo;
  
      private Map&lt;String, String&gt; itemCategoryFields;
  
      public String getNameContains() {
          return nameContains;
      }
  
      public void setNameContains(String nameContains) {
          this.nameContains = nameContains;
      }
  
      public BigDecimal getPriceFrom() {
          return priceFrom;
      }
  
      public void setPriceFrom(BigDecimal priceFrom) {
          this.priceFrom = priceFrom;
      }
  
      public BigDecimal getPriceTo() {
          return priceTo;
      }
  
      public void setPriceTo(BigDecimal priceTo) {
          this.priceTo = priceTo;
      }
  
      public Map&lt;String, String&gt; getItemCategoryFields() {
          return itemCategoryFields;
      }
  
      public void setItemCategoryFields(Map&lt;String, String&gt; itemCategoryFields) {
          this.itemCategoryFields = itemCategoryFields;
      }
  
      /* used when first the form loads*/
      private List&lt;ShelfItems&gt; items;
  
      public List&lt;ShelfItems&gt; getItems() {
          return items;
      }
  
      private DataServiceProviderInterface serviceProvider;
  
      public DataServiceProviderInterface getServiceProvider() {
          return serviceProvider;
      }
  
      public void setServiceProvider(DataServiceProviderInterface serviceProvider) {
          this.serviceProvider = serviceProvider;
      }
  }
  </code></pre>
  
  <p>and ive also written</p>
  
  <pre><code>$.subscribe("reloadGrid", function(){
     $("filterGrid").trigger("reloadGrid");alert("DF");
  });
  </code></pre>
  
  <p>Now whats problem i couldnt understand...
  Plz provide me solution..plz</p>