Struts 2网格没有显示

时间:2016-07-14 04:23:30

标签: java jquery json jsp struts2

您好我正在使用struts 2 jQuery grid插件。但它不起作用。我几乎尝试了一切。但网格没有显示出来。这是我的代码

<s:url var="remoteurl" action="jsontable" />
<sjg:grid id="gridTable" caption="login ID" dataType="json"
    href="%{remoteurl}" pager="true" gridModel="gridModel"
    rowList="10,15,20" rowNum="15" rownumbers="true">
<sjg:gridColumn name="id" title="ID"></sjg:gridColumn>
<sjg:gridColumn name="name" title="Name"></sjg:gridColumn>
<sjg:gridColumn name="mob" title="mobile"></sjg:gridColumn>
</sjg:grid>

struts.xml中

<package name="mypackage" namespace="/" extends="struts-default, json-default">
     <result-types>
            <result-type name="json" class="org.apache.struts2.json.JSONResult" default="true"/>
            <result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult" default="true"/>
        </result-types>
<action name="mis" class="com.action.JsonAction">
        <result name="success">/WEB-INF/jsp/mis.jsp</result>
        <result name="input">/WEB-INF/jsp/mis.jsp</result>
        </action>
        <action name="jsontable" class="com.action.JsonAction">
        <result name="success">/WEB-INF/jsp/mis.jsp</result>
        </action>
</package>

行动CLass

public class JsonAction extends ActionSupport {
    private List<CustomerModel> gridModel;
    private int rows = 0;
    private int page = 0;
    private String sortAsc;
    private String sortIndex;
    private String searchField;
    private String searchOprtn;
    private int total = 0;
    private int records = 0;

    @Override
    public String execute() throws Exception {

        int to = (rows * page);
        int from = to - rows;
        JsonActionDao jsn = new JsonActionDaoImpl();
        records = jsn.getNoOfRecords();
        gridModel = jsn.getRecords();
        total = (int) Math.ceil((double) records / (double) rows);
        System.out.println("row "+rows+"page "+page+"gridModel "+gridModel);
        return "success";
      // getter and setter for fields.,,,....
    }
}

CustomerModel

package com.model;

public class CustomerModel {

    int id;
    String name;
    int mob;
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getMob() {
        return mob;
    }
    public void setMob(int mob) {
        this.mob = mob;
    }
    @Override
    public String toString() {
        return "CustomerModel [id=" + id + ", name=" + name + ", mob=" + mob + "]";
    }

}

我认为我的动作类没有返回json类型的对象。我需要为此做点什么吗?可能会有一些我错过的东西,因为我是像json这样的东西的新手。

1 个答案:

答案 0 :(得分:0)

通过包含struts jq标签解决了问题

<%@taglib uri="/struts-jquery-tags" prefix="sj" %>  

并在以下行

<sj:head jqueryui="true" jquerytheme="redmond" />