简体   繁体   English

使用Java Struts2 jQuery插件将数据从Java Struts2 Action加载到jqGrid时出现问题

[英]Problem with loading data from Java Struts2 Action into jqGrid using Java Struts2 jQuery Plugin

I'm using Java at the core backend and JSP pages as GUI frontend. 我在核心后端使用Java,并在JSP页面上使用GUI前端。 and also I'm using Struts2 to connect JSP Pages to my Java Core. 而且我正在使用Struts2将JSP页面连接到我的Java Core。

struts2 jQuery plugin provides jquery capabilities as struts tags. struts2 jQuery插件提供了struts标签的jquery功能。 see the showcase here : 这里查看展示柜:

now I wanna load 2 very simple 1 columned rows into the grid provided by jQuery Plugin. 现在我想将2个非常简单的1列行加载到jQuery Plugin提供的网格中。 I've got just this tag in my index.jsp: 我的index.jsp中只有这个标签:

<s:url id="remoteurl" action="jsontable"/>
<sjg:grid
    id="gridtable"
    caption="Stocks Examples"
    dataType="json"
    href="%{remoteurl}"
    pager="true"
    gridModel="gridModel"

    rowNum="2"
    rownumbers="true"
>
    <sjg:gridColumn name="id" index="id" title="ID" formatter="integer" sortable="false"/>
</sjg:grid> 

my Struts Action is: 我的Struts Action是:

public String execute() {

            // Count Rows (select count(*) from costumer)
            records = 2;
            rows=2;
            // Your logic to search and select the required data.
            gridModel = new ArrayList<Integer>();
            gridModel.add(15);
            gridModel.add(80);
            // calculate the total pages for the query
            total = (int) Math.ceil((double) records / (double) rows);
            System.out.println("I'm a JSON Action ");
            return SUCCESS;
    }

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

Finally the struts XML Config file: 最后是struts XML Config文件:

<struts>
  <constant name="struts.enable.DynamicMethodInvocation" value="true" /

  <constant name="struts.devMode" value="false" />
  <constant name="struts.custom.i18n.resources"
value="ApplicationResources" />

  <package name="default" extends="struts-default,json-default" >

  <action name="jsontable" class="strutsAction.JsonTable" >
      <result type="json" name="success"></result>
  </action>

  </package>
</struts>

I expect to see two rows in my one columned grid representing the values: 15 and 80 as I set them in the Struts Action. 我希望在我的一栏网格中看到两行代表值:在Struts Action中设置它们时,分别为15和80。 But What I get is two rows, both 0 但是我得到的是两行,都为0

any ideas? 有任何想法吗?

Here is a completely working JQGrid Example in Netbeans 6.9. 这是Netbeans 6.9中一个完全可用的JQGrid示例。

EditableSortableSearchableStruts2JqueryGrid EditableSortableSearchableStruts2JqueryGrid

Simply resolve the references and get going. 只需解决参考资料并开始使用。

Instead of directly populating the gridModel do this stuff : 而不是直接填充gridModel,而是这样做:

List temp=new ArrayList(); 列出temp = new ArrayList();

temp.add(12); temp.add(12);

temp.add(140); temp.add(140);

setGridModel(temp); setGridModel(温度);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM