简体   繁体   中英

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. and also I'm using Struts2 to connect JSP Pages to my Java Core.

struts2 jQuery plugin provides jquery capabilities as struts tags. see the showcase here :

now I wanna load 2 very simple 1 columned rows into the grid provided by jQuery Plugin. I've got just this tag in my 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:

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>
  <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. But What I get is two rows, both 0

any ideas?

Here is a completely working JQGrid Example in Netbeans 6.9.

EditableSortableSearchableStruts2JqueryGrid

Simply resolve the references and get going.

Instead of directly populating the gridModel do this stuff :

List temp=new ArrayList();

temp.add(12);

temp.add(140);

setGridModel(temp);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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