我正在尝试使用 struts2-jquery 网格插件。调试时,我的 gridmodel 得到了正确更新,但网格上没有显示任何内容。这是我的动作课:
private List<Customer> gridModel;
private Integer rows ;
private Integer page ;
private String sord;
private String sidx;
private String searchField;
private String searchString;
private String searchOper;
private Integer total ;
private Integer records ;
public String execute() throws Exception{
try {
List<Customer> list = new ArrayList<Customer>;
for (int i=0; i<3; i++) {
Customer cust = new Customer("myName", 20, "myAdress", "23651336");
list.add(cust);
}
setGridModel(list);
setRecords(list.size());
total =(int) Math.ceil((double)records / (double)rows);
} catch( Exception e) {
log.error("Error in JSON data : " +e.getMessage());
}
return SUCCESS;
}
public List<Customer> getGridModel() {
return gridModel;
}
public Integer getPage() {
return page;
}
public void setPage(Integer page) {
this.page = page;
}
public String getSearchField() {
return searchField;
}
public void setSearchField(String searchField) {
this.searchField = searchField;
}
public void setGridModel(List<Customer> 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 Integer getRecords() {
return records;
}
public void setRecords(Integer records) {
this.records = records;
if (this.records > 0 && this.rows > 0)
{
this.total = (int) Math.ceil((double) this.records / (double) this.rows);
}
else
{
this.total = 0;
}
}
public String getSearchOper() {
return searchOper;
}
public void setSearchOper(String searchOper) {
this.searchOper = searchOper;
}
public Integer getTotal() {
return total;
}
public void setTotal(Integer total) {
this.total = total;
}
public String getSearchString() {
return searchString;
}
public void setSearchString(String searchString) {
this.searchString = searchString;
}
public Integer getRows() {
return rows;
}
public void setRows(Integer rows) {
this.rows = rows;
}
我将以下网格定义添加到我的 jsp 中:
<s:url id="remoteurl" action="jsontable"/>
<sjg:grid
id="gridtable"
caption="Listes "
dataType="json"
href="%{remoteurl}"
pager="true"
gridModel="gridModel"
rowList="10,15,20"
rowNum="15"
rownumbers="true"
>
<sjg:gridColumn name="name" index="name" title="Name" />
<sjg:gridColumn name="age" index="age" title="Age"/>
<sjg:gridColumn name="adress" index="adress" title="Adress" />
<sjg:gridColumn name="tel" index="tel" title="Tel" />
</sjg:grid>
在 struts.xml 中,我使用结果类型 json 声明我的操作
<package name="default" extends="json-default,struts-default" namespace="/">
<result-types>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />
<result-type name="json" class="org.apache.struts2.json.JSONResult" />
</result-types>
<action name="jsontable" class="com.web.action" method="execute" >
<result name="success" type = "json"></result>
</action>
</package>
拜托,你能告诉我我错过了什么吗