I'm trying to populate my flexigrid in a JSP page. I am successfully
hitting the "doGet" overridden method, which then calls the userSearch
method. At the end of the userSearch method, it is putting the
objects into a WebReturn class, which simply formats the JSON object
for me. At the bottom, I posted exactly what the JSON return object
looks like. The flexigrid is never populated, however. Can anyone
spot what I've missed?
JSP PAGE
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
<script type="text/javascript" src="jquery-1.6.2.min.js" ></script>
<script type="text/javascript" src="utils.js" ></script>
<script type="text/javascript" src="js/flexigrid.js"></script>
<link rel="stylesheet" type="text/css" href="css/flexigrid.css" />
<link rel="stylesheet" type="text/css" href="css/style.css" />
<script language=JavaScript>
function callback(data, status) {
alert("Test 1");
}
$(function() {
$("#userGrid").flexigrid({
url: 'FlexigridTest/UserSearch',
method: 'GET',
dataType: 'json',
colModel : [
{display: 'Email', name : 'email', width : 40, sortable : true,
align: 'center'}
],
searchitems : [
{display: 'Email', name : 'email', isdefault: true}
],
sortname: "email",
sortorder: "asc",
usepager: true,
title: 'Users',
useRp: true,
rp: 15,
showTableToggleBtn: true,
width: 700,
height: 200
});
});
</script>
<title>User Search</title>
</head>
<body>
<p><u>Users</u></p>
<table name="userGrid" id="userGrid" ></table>
<p> </p>
</body>
</html>
SERVLET
@Override
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
searchUsers(request, response);
}
public void searchUsers(HttpServletRequest request,
HttpServletResponse response) {
System.out.println(" --> searchUsers called! ");
HibernateSessionUtil hsu = HibernateUtil.openHSU();
hsu.beginTransaction();
Criteria crit = hsu.getSession().createCriteria(LoginUser.class);
List<LoginUser> users = crit.list();
JSONArray jArray = new JSONArray();
for(LoginUser user : users) {
try {
JSONObject jsonObj = new JSONObject();
jsonObj.put("id", "email");
jsonObj.put("cell", user.getEmail_address());
jArray.put(jsonObj);
} catch (JSONException ex) {
java.util.logging.Logger.getLogger(UserSearch.class.getName()).log(Level.SEVERE,
null, ex);
}
}
WebReturn ret = new WebReturn(response);
ret.put("page", 1);
ret.put("total", users.size());
ret.put("rows", jArray);
ret.reply();
}
JSON Returned Object:
{"total":4,"page":1,"rows":[{"id":"email","cell":"
te...@test.com"},
{"id":"email","cell":"
as...@asdf.com"},
{"id":"email","cell":"
jfjfj...@jfjfjfj.com"},
{"id":"email","cell":"
te...@test2.com"}]}