Help Populating Flexigrid from Java Servlet

550 views
Skip to first unread message

derekadams32

unread,
Aug 25, 2011, 5:18:59 PM8/25/11
to Flexigrid for jQuery
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>&nbsp;</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"}]}

Sarbajit Chatterjee

unread,
Aug 29, 2011, 12:08:25 PM8/29/11
to flex...@googlegroups.com
I can spot a mistake -

Each "cell" should be one string array. You've used "cell" as a string only.
This should solve the problem.

"cell" : ["a...@company.com"]

-Sarbajit





--
You received this message because you are subscribed to the Google Groups "Flexigrid for jQuery" group.
To post to this group, send email to flex...@googlegroups.com.
To unsubscribe from this group, send email to flexigrid+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/flexigrid?hl=en.


Reply all
Reply to author
Forward
0 new messages