我正在尝试使用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>
拜托,能否告诉我我缺少的东西
答案 0 :(得分:0)
当我将动作放入新的动作中时,问题就解决了,而不是在另一个动作中。