我正在尝试将 struts2 动作类中的数据显示到 JQuery Grid 中。但是当我尝试实现这一点时,我什至没有得到网格,它只是将 JSON 字符串显示为输出,如下所示,尝试了此处发布的所有其他答案,但没有运气..:(
{
"dummyData": [
{
"email": "ABC",
"name": "DEF"
}
],
"page": null,
"records": 1,
"resDetailObj": {
"email": "ABC",
"name": "DEF"
},
"rows": 0,
"searchField": null,
"searchOper": null,
"searchString": null,
"sidx": null,
"sord": null,
"total": 2147483647
}
我正在使用 struts2-jquery-grid-plugin-3.5.1.jar、struts2-jquery-plugin-3.2.1.jar 和 struts2-json-plugin-2.1.8.jar
我的jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org /TR/html4/loose.dtd">
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sjg" uri="/struts-jquery-grid-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags" %>
<html>
<h1>In JQueryGrid</h1>
<head>
<sj:head jqueryui="true" jquerytheme="redmond"/>
</head>
<body>
<s:url var="remoteurl" action="grid"/>
<sjg:grid
id="mygrid"
caption="My Details"
dataType="json"
href="%{remoteurl}"
pager="true"
gridModel="dummyData"
>
<sjg:gridColumn name="name" index="name" title="Name"
sortable="true"/>
<sjg:gridColumn name="email" index="email" title="Email"
sortable="true"/>
</sjg:grid>
</body>
</html>
我的 struts.xml 文件是
<package name="JQueryGrid" namespace="/" extends="struts-default">
<action name="grid class="com.digi.crystal.resourceutilization.actions.GridAction">
<result name="success" type="json">
/JqueryGrid.jsp
</result>
</action>
</package>
最后我的动作课是
public class GridAction extends ActionSupport
{
private List<CResourceDetails> dummyData;
private Integer rows=0;
private Integer page;
private String sord;
private String sidx;
private String searchField;
private String searchString;
private String searchOper;
private Integer total;
private Integer records;
private CResourceDetails resDetailObj = new CResourceDetails();
public GridAction()
{
}
public String execute()
{
List<CResourceDetails> temp = new ArrayList<CResourceDetails>();
resDetailObj.setEmail("ABC");
resDetailObj.setName("DEF");
temp.add(resDetailObj);
setDummyData(temp);
System.out.println("The temp is:"+"in execute"+dummyData.size()+","+rows);
setRecords(temp.size());
total =(int) Math.ceil((double)records / (double)rows);
System.out.println("the total is:"+total/1000000000);
return Action.SUCCESS;
}
// getters and setters of attributes
这里 CResourceDetails 只是一个普通的 POJO,带有名称和电子邮件。
如果有人可以帮助我处理这个网格,那对我来说将是一个很大的帮助。
非常感谢提前,
CSSiddartha