Note that there are some explanatory texts on larger screens.

plurals
  1. POStruts2-Jquery Grid : Data not getting displayed
    primarykey
    data
    text
    <p>I'm using struts2-jquery grid.</p> <p>gridmodel in my action class is getting updated correctly. But, nothing is getting displayed on the grid.</p> <p><strong>struts.xml</strong></p> <pre><code>&lt;struts&gt; &lt;package name="default" namespace="/searchAndUpdate" extends="struts-default,json-default"&gt; &lt;action name="listUsers" class="com.pilot.web.action.ListUsers" method="getJSON"&gt; &lt;result name="success"&gt;/jsp/userList.jsp&lt;/result&gt; &lt;result name="input"&gt;/jsp/userList.jsp&lt;/result&gt; &lt;/action&gt; &lt;/package&gt; </code></pre> <p></p> <p><strong>userList.jsp</strong></p> <pre><code>&lt;%@ page contentType="text/html; charset=UTF-8"%&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 XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt; &lt;head&gt; &lt;sj:head jqueryui="true" jquerytheme="redmond"/&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;meta http-equiv="Content-Style-Type" content="text/css" /&gt; &lt;/head&gt; &lt;body&gt; &lt;h3&gt;Application Users&lt;/h3&gt; &lt;s:actionerror/&gt; &lt;s:actionmessage/&gt; &lt;s:url id="remoteurl" action="/searchAndUpdate/listUsers"/&gt; &lt;sjg:grid id="gridtable" caption="Application Users" dataType="json" href="%{remoteurl}" pager="true" gridModel="gridModel" rowList="10,15,20" rowNum="15" rownumbers="true" resizable="true" viewrecords="true" &gt; &lt;sjg:gridColumn name="id" index="id" title="Id" formatter="integer" sortable="false"/&gt; &lt;sjg:gridColumn name="userName" index="userName" title="User Name" sortable="true"/&gt; &lt;sjg:gridColumn name="fullName" index="fullName" title="Full Name" sortable="false"/&gt; &lt;sjg:gridColumn name="email" index="email" title="EMail" sortable="false"/&gt; &lt;/sjg:grid&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>ListUsers.java</strong></p> <pre><code>package com.pilot.web.action; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import com.opensymphony.xwork2.ActionSupport; import com.oxxo.pilot.backend.jdbc.dao.impl.User; public class ListUsers extends ActionSupport { private static final long serialVersionUID = 1L; private List&lt;User&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; // Your Total Pages private Integer total = 0; // All Records private Integer records = 0; // sorting order - asc or desc private String sord; // get index row - i.e. user click to sort. private String sidx; public String getAllApplicationData() { List&lt;User&gt; users = userListFromDb(); if (users != null &amp;&amp; getSord() != null &amp;&amp; getSord().equalsIgnoreCase("asc")) { Collections.sort(users, null); } if (getSord() != null &amp;&amp; "desc".equalsIgnoreCase(getSord())) { Collections.sort(users, null); Collections.reverse(users); } setRecord(users.size()); int to = (getRows() * getPage()); if (to &gt; getRecord()) to = getRecord(); setGridModel(users); setTotal((int) Math.ceil((double) getRecord() / (double) getRows())); System.out.println("Total is : " + getTotal()); System.out.println("Record is : " + getRecord()); for(User user: users){ System.out.println(user.getUserName() + ", " + user.getFullName() + ", " + user.getEmail()); } if (hasActionMessages() || hasActionErrors()) { return INPUT; } return SUCCESS; } private List&lt;User&gt; userListFromDb() { // MOCKED List for now List&lt;User&gt; users = new ArrayList&lt;User&gt;(); User user1 = new User(); user1.setId(1); user1.setUserName("user1"); user1.setFullName("User ABC"); user1.setEmail("user1@email.com"); User user2 = new User(); user2.setId(1); user2.setUserName("user2"); user2.setFullName("User DEF"); user2.setEmail("user2@email.com"); users.add(user1); users.add(user2); return users; // TODO FETCH LIST OF USERS FROM DB } public String getJSON() { System.out.println("here in getJSON"); return getAllApplicationData(); } 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 Integer getTotal() { return total; } public void setTotal(Integer total) { this.total = total; } public Integer getRecord() { return records; } public void setRecord(Integer records) { this.records = records; if (this.records &gt; 0 &amp;&amp; this.rows &gt; 0) { this.total = (int) Math.ceil((double) this.records / (double) this.rows); } else { this.total = 0; } } public List&lt;User&gt; getGridModel() { return gridModel; } public void setGridModel(List&lt;User&gt; gridModel) { this.gridModel = gridModel; } 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 void setSearchField(String searchField) { } public void setSearchString(String searchString) { } public void setSearchOper(String searchOper) { } public void setLoadonce(boolean loadonce) { } public void setSession(Map&lt;String, Object&gt; session) { } } </code></pre> <p>I did refer to the solution on <a href="https://stackoverflow.com/questions/6411589/struts2-jquery-grid-data-not-load?answertab=active#tab-top">struts2 jquery grid data not load?</a></p> <p>But that solution did not work. Instead of data getting displayed on the grid, it prompted to save the file &amp; that file contained the following info:</p> <blockquote> <p>{"JSON":"success","gridModel":[{"email":"user1@email.com","fullName":"User ABC","id":1,"userName":"user1"},{"email":"user2@email.com","fullName":"User DEF","id":1,"userName":"user2"}],"page":0,"record":2,"rows":0,"sidx":null,"sord":null,"total":2147483647}*</p> </blockquote> <p>As per my understanding row &amp; page are automatically handled by the plugin. But as per the json data above they are not getting incremented. Hard-coded them to the size of the gridmodel and the json data I got is:</p> <blockquote> <p><em>{"JSON":"success","allApplicationData":"success","gridModel":[{"email":"user1@email.com","fullName":"User ABC","id":1,"userName":"user1"},{"email":"user2@email.com","fullName":"User DEF","id":1,"userName":"user2"}],"page":1,"record":2,"rows":2,"sidx":null,"sord":null,"total":1}</em></p> </blockquote> <p>On updating struts.xml as</p> <pre><code> &lt;result-types&gt; &lt;result-type name="json" class="org.apache.struts2.json.JSONResult" /&gt; &lt;/result-types&gt; &lt;action name="listUsers" class="com.oxxo.pilot.web.action.ListUsers"&gt; &lt;result name="success" type="json"&gt;/jsp/userList.jsp&lt;/result&gt; &lt;result name="input" type="json"&gt;/jsp/userList.jsp&lt;/result&gt; &lt;/action&gt; </code></pre> <p>the json data is displayed on the browser.</p> <p>Thanks, Shikha</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload