Hi
Actually I just use Struts2 XML Config, I was testing other ways
above.
I checked the XML Http Request with firebug, it loads successfully and
the JSON result in response is this:
{"JSON":"success","gridModel":[15,80],"page":1,"records":2,"rows":
2,"searchField":null,"searchOper":null,"searchString":null,"sidx":"","sord":"asc","total":
1}
Again 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();
}
And here's the Grid in the 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>
Finally the struts Config file:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"
http://struts.apache.org/dtds/struts-2.0.dtd">
<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>
nevertheless I get a grid with two 0 valued rows.
Waht's wrong?