gpt4 book ai didi

jquery - Struts2 jQuery 网格数据未加载

转载 作者:行者123 更新时间:2023-12-04 06:22:14 24 4
gpt4 key购买 nike

我是 JQgrid 和 Struts2 的初学者。

我曾尝试使用此代码,但网格中没有记录,但我得到了所有记录。

测试网格.jsp

<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<%@ taglib prefix="sjg" uri="/struts-jquery-grid-tags"%>

......
.......
<s:url id="remoteurl" action="jsontable"/>
<sjg:grid
id="gridtable"
caption="Application Data"
dataType="json"
href="%{remoteurl}"
pager="true"
gridModel="gridModel"
rowList="10,15,20"
rowNum="15"
rownumbers="true"
>
<sjg:gridColumn name="state" index="state" title="State" sortable="true"/>
<sjg:gridColumn name="city" index="city" title="City" sortable="false"/>
<sjg:gridColumn name="district" index="district" title="District" sortable="false"/>
</sjg:grid>

测试 Action .java
package com.sttl.rpsc.action;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import com.sttl.rpsc.action.base.BaseAction;
import com.sttl.rpsc.dataobject.Application;
import com.sttl.rpsc.util.HibernateUtil;

public class testAction extends BaseAction {


private List<Application> gridModel;
private List<Application> myCustomers;
private Integer rows = 0;
private Integer page = 0;
private Integer total = 0;
private Integer record = 0;
private String sord;
private String sidx;
private String searchField;
private String searchString;
private String searchOper;
private boolean loadonce = false;



public List<Application> getGridModel() {
return gridModel;
}
public void setGridModel(List<Application> gridModel) {
this.gridModel = gridModel;
}
public List<Application> getMyCustomers() {
return myCustomers;
}
public void setMyCustomers(List<Application> myCustomers) {
this.myCustomers = myCustomers;
}
public Integer getRows() {
return rows;
}
public void setRows(Integer rows) {
this.rows = rows;
}
public Integer getPage() {
return page;
}
public void setPage(Integer page) {
this.page = page;
}
public Integer getTotal() {
return total;
}
public void setTotal(Integer total) {
this.total = total;
}
public Integer getRecord() {
return record;
}
public void setRecord(Integer record) {
this.record = record;
}
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 String getSearchField() {
return searchField;
}
public void setSearchField(String searchField) {
this.searchField = searchField;
}
public String getSearchString() {
return searchString;
}
public void setSearchString(String searchString) {
this.searchString = searchString;
}
public String getSearchOper() {
return searchOper;
}
public void setSearchOper(String searchOper) {
this.searchOper = searchOper;
}
public boolean isLoadonce() {
return loadonce;
}
public void setLoadonce(boolean loadonce) {
this.loadonce = loadonce;
}

public String getJSON()
{
return getAllApplicationData();
}

public String getAllApplicationData(){
String result = SUCCESS;

Query q = null;
try{

Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
q = session.createQuery("from Application");
this.setGridModel(q.list());

if(this.getGridModel()!=null)
System.out.println("gridModel.Size() : "+this.getGridModel().size());
else
System.out.println("gridModel null");

int to = (rows * page);
int from = to - rows;


//Count Rows (select count(*) from custumer)
record = gridModel.size();

System.out.println("record : "+record);
//Your logic to search and select the required data.
//gridModel = CustumerDAO.find(from, to);


//calculate the total pages for the query
total =(int) Math.ceil((double)record / (double)rows);
System.out.println("total : "+total);

}catch(Exception e){
e.printStackTrace();
}

return result;
}



}

struts.xml
<package name="default" extends="struts-default,json-default" namespace="/">

..........
...........

<action name="jsontable" class="com.sttl.rpsc.action.testAction" method="getJSON">
<interceptor-ref name="basicStack" />
<result name="success" type="tiles">/testgrid.tiles</result>
<result name="error" type="redirect">/testgrid.tiles</result>
<result name="cancel" type="redirect">/testgrid.tiles</result>
</action>

瓷砖.xml
<definition name="/testgrid.tiles" extends="baseLayoutNew">
<put-attribute name="title" value="Test Grid" />
<put-attribute name="body" value="/jsp/examination/testGrid.jsp" />
</definition>

在这里,我得到了列表大小:183,当我在操作文件中迭代时,我得到了所有记录,但无法进入网格。我该怎么办?那里没有错误显示。

最佳答案

在您的网格中,您希望重新调整 JSON。因此,在您的 Action 映射中,您必须将结果类型更改为 json作为:

<action name="jsontable" class="com.sttl.rpsc.action.testAction" method="getJSON">
<result name="success" type="json"/>
</action>
json结果类型由 Struts2 JSON plugin 添加到您的结果类型中.确保插件在您的类路径中并且您的包正在扩展 json-default .通过指定 json作为您的结果类型,您将您的操作序列化为 JSON,使其可用于 javascript 代码(在您的情况下为网格)来读取数据。

关于jquery - Struts2 jQuery 网格数据未加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6411589/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com