Struts 2 JQuery Grid没有显示出来

时间:2013-04-04 09:12:59

标签: struts2 struts2-jquery struts2-jquery-grid

我试图将struts2动作类中的数据显示到JQuery Grid中。但是当我试图实现这一点时,我甚至没有得到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>

最后我的Action类是

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,带有名称和电子邮件。

如果有人能帮助我使用这个网格,那对我来说将是一个很大的帮助。

提前多多感谢,

C.S.Siddartha

2 个答案:

答案 0 :(得分:0)

我认为您正在直接访问操作网格:

http://localhost:8080/JQueryGrid/grid.action

尝试访问jsp:

http://localhost:8080/JQueryGrid/JqueryGrid.jsp

然后网格将调用该操作并检索结果。

答案 1 :(得分:0)

Siddarth首先在struts中编写一个动作,结果只映射到包含网格的JSP页面然后只用json对网格进行操作

<package name="JQueryGrid" namespace="/" extends="struts-default,json-default">
 <action name="opengridJSP" class="com.digi.crystal.resourceutilization.actions.GridAction" method ="SomeMethod">
    <result name="success">/JqueryGrid.jsp</result>
</action>

<action name="grid class="com.digi.crystal.resourceutilization.actions.GridAction">
    <result name="success" type="json"/>
</action>
</package>