使用struts2-jquery-grid插件在Struts2中使用网格 [英] Grid in Struts2 using struts2-jquery-grid plugin

查看:137
本文介绍了使用struts2-jquery-grid插件在Struts2中使用网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用

I'm trying with a Struts jQuery grid using the struts2-jquery-grid-3.7.0 plugin as demonstrated on the showcase, Grid (Editable/Multiselect).

Struts表单:

<s:form namespace="/admin_side" action="Test" validate="true" id="dataForm" name="dataForm">
    <s:url id="remoteurl" action="TestGrid" namespace="/admin_side"/>
    <s:url id="editurl" action="edit-grid-entry"/>
    <sjg:grid
        id="gridmultitable"
        caption="Example (Editable/Multiselect)"
        dataType="json"
        href="%{remoteurl}"
        pager="true"
        navigator="true"
        navigatorSearchOptions="{sopt:['eq','ne','lt','gt']}"
        navigatorAddOptions="{height:280, width:500, reloadAfterSubmit:true}"
        navigatorEditOptions="{height:280, width:500, reloadAfterSubmit:false}"
        navigatorEdit="true"
        navigatorView="true"
        navigatorViewOptions="{height:280, width:500}"
        navigatorDelete="true"
        navigatorDeleteOptions="{height:280, width:500,reloadAfterSubmit:true}"
        gridModel="gridModel"
        rowList="5,10,15"
        rowNum="5"
        rownumbers="true"
        editurl="%{editurl}"
        editinline="true"
        multiselect="true"
        onSelectRowTopics="rowselect"
        >

        <sjg:gridColumn name="countryId" index="countryId" title="Id" formatter="integer" editable="false" sortable="true" search="true" sorttype="integer" searchoptions="{sopt:['eq','ne','lt','gt']}"/>
        <sjg:gridColumn name="countryName" index="countryName" title="Country Name" editable="true" edittype="text" sortable="true" search="true" sorttype="text"/>
        <sjg:gridColumn name="countryCode" index="countryCode" title="Country Code" sortable="true" search="true" editable="true" sorttype="text"/>

    </sjg:grid>
</s:form>

动作类:

@Namespace("/admin_side")
@ResultPath("/WEB-INF/content")
@ParentPackage(value = "json-default")
@InterceptorRefs(@InterceptorRef(value = "store", params = {"operationMode", "AUTOMATIC"}))
public final class TestAction extends ActionSupport implements Serializable
{
    @Autowired
    private final transient CountryService countryService=null;
    private static final long serialVersionUID = 1L;
    // Result List
    private List<Country> gridModel;
    // Get how many rows we want to have into the grid - rowNum attribute in the grid
    private Integer rows=5;
    // Get the requested page. By default grid sets this to 1.
    private Integer page=1;
    // sorting order - asc or desc
    private String sord;
    // get index row - i.e. user click to sort.
    private String sidx;
    // Search Field
    private String searchField;
    // The Search String
    private String searchString;
    // The Search Operation ['eq','ne','lt','le','gt','ge','bw','bn','in','ni','ew','en','cn','nc']
    private String searchOper;
    // Your Total Pages
    private Integer total;
    // All Records
    private Integer records;

    @Action(value = "TestGrid",
    results = {
        @Result(name = ActionSupport.SUCCESS, type = "json", params = {"includeProperties", "gridModel\\[\\d+\\]\\.countryId, gridModel\\[\\d+\\]\\.countryName, gridModel\\[\\d+\\]\\.countryCode", "excludeNullProperties", "true"})},
    interceptorRefs = {
        @InterceptorRef(value = "json")})
    public String execute() {
        records=countryService.rowCount().intValue();
        total=new BigDecimal(records).divide(new BigDecimal(rows), 0, BigDecimal.ROUND_CEILING).intValue();
        gridModel=countryService.getList(page, rows, null, null);

        System.out.println("records "+records+" total "+total+" Page " + getPage() + " Rows " + getRows() + " Sort Order " + getSord() + " Index Row :" + getSidx()+"Search :" + searchField + " " + searchOper + " " + searchString);
        return SUCCESS;
    }

    public String getJSON() {
        return execute();
    }

    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 getRecords() {
        return records;
    }

    public void setRecords(Integer records) {
        this.records = records;            
    }

    public List<Country> getGridModel() {
        return gridModel;
    }

    public void setGridModel(List<Country> 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) {
        this.searchField = searchField;
    }

    public void setSearchString(String searchString) {
        this.searchString = searchString;
    }

    public void setSearchOper(String searchOper) {
        this.searchOper = searchOper;
    }

    @Action(value = "Test",
    results = {
        @Result(name = ActionSupport.SUCCESS, location = "Test.jsp"),
        @Result(name = ActionSupport.INPUT, location = "Test.jsp")},
    interceptorRefs = {
        @InterceptorRef(value = "defaultStack", params = {"validation.validateAnnotatedMethodOnly", "true", "validation.excludeMethods", "load"})})
    public String load() throws Exception {
        return ActionSupport.SUCCESS;
    }
}

下一个和上一个分页链接始终被禁用,如跟踪快照中所示射击.

The next and previous pagination links are always disabled as shown in the following snap shot.

它表示第1页(共1页).没有更多页面.因此,链接被禁用.

It indicates, page 1 of 1. There are no more pages. Hence, the links are disabled.

但是,在execute()方法中,records初始化为31total初始化为7 Page1 Rows5.无论是否单击用于排序,搜索,编辑,添加行的链接/按钮,所有其他属性均始终为空.

In the execute() method, however, records is initialized to 31, total to 7 Page to 1 Rows to 5. All other properties are always null whether or not links/buttons for sorting, searching, editing, adding a row are clicked.

我在这里俯瞰什么?

推荐答案

您忘记了为json结果添加字段,这些字段是网格正常运行所必需的.更改为

You forgot to include fields to json result that are necessary for grid to function properly. Change to

@Result(type = "json", params = {"includeProperties", "gridModel\\[\\d+\\]\\.countryId, gridModel\\[\\d+\\]\\.countryName, gridModel\\[\\d+\\]\\.countryCode, total, records, rows, page, sord, sidx, searchField, searchString, searchOper",  "excludeNullProperties", "true"})

此外,json拦截器不是必需的,但params是必需的.

Also, json interceptor is not necessary, but params is required.

@InterceptorRef("params") 

这篇关于使用struts2-jquery-grid插件在Struts2中使用网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆