Hi I am working with struts 2 jQuery grid plugin. But Its not working. I tried almost everything. But grid is not getting displayed. Here is my code
<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>
Action 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 + "]";
}
}
I think my action class is not returning a object of type json. Do i need to do something for that. Might be there is something that I am missing out since I am new to the stuffs like json.