我很新玩并开始使用play 2.0。
试图查看 jqgrid 但无法显示数据,下面是代码:
控制器 :
public static Result userLogs(String criteria) throws JSONException {
JSONObject responcedata = new JSONObject();
JSONArray logData = UserLogs.getUserlogs();
responcedata.put("page", 1);
responcedata.put("records", 10);
responcedata.put("rows", logData);
response().setContentType("application/json");
return ok(userlogs.render(responcedata));
}
模型类:
公共静态 JSONArray getUserlogs() {
String query = "select date from user where user_id=1 and resp=1";
List<SqlRow> userLogs = Ebean.createSqlQuery(query).findList();
JSONArray cellarray = new JSONArray();
int tableSize = userLogs.size();
int i = 0;
while (i < tableSize) {
JSONObject cellObj = new JSONObject();
JSONArray cell = new JSONArray();
cell.put(i + 1);
cell.put(userLogs.get(i).getTimestamp("date"));
try {
cellObj.put("cell", cell);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
cellarray.put(cellObj);
i++;
}
return cellarray;
}
看法 :
jQuery("#grid").jqGrid({
url:"@Application.userLogs(),
datatype : 'json',
colNames:['S.No','date'],
colModel:[
{name:'sno',index:'sno', width:50, sorttype:"int"},
{name:'date',index:'date', width:150, sorttype:"date"}
],
jsonReader : {
root: "rows",
page: "page",
total: "total",
records: "records",
cell: "cell",
loadOnce: "true",
id: "id",
userdata: "userdata"
},
width: 900,
height: 220,
rowNum:10, rowList:[10,20,30],
pager: '#pager',
sortname: 'id',
viewrecords: true,
gridview: true,
sortorder: "desc",
loadonce:true,
ignoreCase:true,
multiselect: true,
});
});
以下是例外::
play.api.Application$$anon$1: play.api.Application$class.handleError(Application.scala:289) 处的执行异常[[RuntimeException: java.lang.StackOverflowError]] ~[play_2.10.jar:2.1. 1] 在 play.api.DefaultApplication.handleError(Application.scala:383) [play_2.10.jar:2.1.1] 在 play.core.server.netty.PlayDefaultUpstreamHandler$$anon$2$$anonfun$handle$1.apply (PlayDefaultUpstreamHandler.scala:144) [play_2.10.jar:2.1.1] 在 play.core.server.netty.PlayDefaultUpstreamHandler$$anon$2$$anonfun$handle$1.apply(PlayDefaultUpstreamHandler.scala:140) [play_2. 10.jar:2.1.1] 在 play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10.jar:2.1.1] 在 play.api.libs .concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10.jar:2.1.1] java.lang.RuntimeException: java.lang.StackOverflowError at play.libs.F$Promise$6.apply(F.java:401) ~[play_2.10.jar:2.1.1] at scala.concurrent.Future$$anonfun$map$1.liftedTree2$1(Future .scala:253) ~[scala-library.jar:na] at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:249) ~[scala-library.jar:na] at scala.concurrent .Future$$anonfun$map$1.apply(Future.scala:249) ~[scala-library.jar:na] at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:29) ~[scala-library. jar:na] at akka.dispatch.BatchingExecutor$Batch$$anonfun$run$1.liftedTree1$1(BatchingExecutor.scala:67) ~[akka-actor_2.10.jar:na] java.lang.StackOverflowError: null at com. mysql.jdbc.Util.handleNewInstance(Util.java:431) ~[mysql-connector-java-5.1.18.jar:na] at com.mysql.jdbc.PreparedStatement.getInstance(PreparedStatement.java:第872章~[mysql-connector-java-5.1.18.jar:na]在com.mysql.jdbc.ConnectionImpl.clientPrepareStatement(ConnectionImpl.java:1490)~[mysql-connector-java-5.1.18.jar:na] ] 在 com.mysql.jdbc.ConnectionImpl.prepareStatement(ConnectionImpl.java:4253) ~[mysql-connector-java-5.1.18.jar:na] 在 com.mysql.jdbc.ConnectionImpl.prepareStatement(ConnectionImpl.java:4152 ) ~[mysql-connector-java-5.1.18.jar:na] at com.jolbox.bonecp.ConnectionHandle.prepareStatement(ConnectionHandle.java:820) ~[bonecp.jar:0.7.1.RELEASE]prepareStatement(ConnectionImpl.java:4152) ~[mysql-connector-java-5.1.18.jar:na] at com.jolbox.bonecp.ConnectionHandle.prepareStatement(ConnectionHandle.java:820) ~[bonecp.jar:0.7.1 。发布]prepareStatement(ConnectionImpl.java:4152) ~[mysql-connector-java-5.1.18.jar:na] at com.jolbox.bonecp.ConnectionHandle.prepareStatement(ConnectionHandle.java:820) ~[bonecp.jar:0.7.1 。发布]
请让我知道如何处理这种情况并使用 jqgrid 在视图中显示列表。实现这一目标的任何替代方法也有帮助。
谢谢..!!!