struts2.0+easyUI实现dataGrid,纠结~!
先跟大家说一下我遇到的问题:我用的SSH框架,用的注解,就是想把获取到的list转换成easyUI的Json,然后发送到jsp页面,生成列表,目前我能把list转换成Json对象,而且格式符合easyUI的格式规范,就是不能把Json放到jsp的列表中去。运行jsp页面的时候只能显示一个列表框,没有任何信息!
下面是我的代码:
Action 类:
/**
* 获取角色列表
*
* @author chenj 2010-9-14
*/
@Action(value = "select", results = { @Result(name = "error", location = "/role/saveError.jsp", type = "redirect"),
@Result(name = "success", location = "/role/saveSuccess.jsp", type = "redirect") })
public String getAllUmRole() {
String result = "";
String Json = "";
HttpServletResponse response = ServletActionContext.getResponse();
try {
JSONArray a = new JSONArray();
PrintWriter out = response.getWriter();
List<UmRole> list = entityManager.getAll(UmRole.class);
for (UmRole obj : list) {
a.add(ModelHelper.getInstance().toJSON(obj, true));
}
Json = a.toJSON(false);
out.print(Json.toString());
System.out.println(Json.toString());
result = com.opensymphony.xwork2.Action.SUCCESS;
} catch (Exception e) {
e.printStackTrace();
result = com.opensymphony.xwork2.Action.ERROR;
}
return result;
}
备注:有些类跟方法是自己封装的
JSP页面代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>jQuery EasyUI</title>
<link rel="stylesheet" type="text/css" href="../jqueryeasyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../jqueryeasyui/themes/icon.css">
<script type="text/javascript" src="../jqueryeasyui/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="../jqueryeasyui/jquery.easyui.min.js"></script>
<script>
$(function(){
$('#tt').datagrid({
title:'Load Data',
iconCls:'icon-save',
width:600,
height:250,
type:'Json',
url:'select.do',
frozenColumns:[[
{field:'id',checkbox:true}
]],
columns:[[
{field:'id',title:'id',width:80},
{field:'name',title:'name',width:80},
{field:'des',title:'des',width:80,align:'right'}
]],
pagination:true,
toolbar:[{
id:'btnadd',
text:'新增',
iconCls:'icon-add',
handler:function(){
$('#btnsave').linkbutton('enable');
openNewPage('openCreatePage.do');
}
},{
id:'btncut',
text:'修改',
iconCls:'icon-cut',
handler:function(){
$('#btnsave').linkbutton('enable');
updatePoJo('openUpdatePage.do');
}
},{
id:'btnadd',
text:'删除',
iconCls:'icon-cancel',
handler:function(){
$('#btnsave').linkbutton('enable');
deletePoJo('delete.do');
}
}]
});
});
function deletePoJo(action){
var ids=document.getElementsByName("id");
var id = "";
var num = 0;
for(var i=0;i<ids.length;i++){
if(ids[i].checked){
id += ids[i].value+",";
num++;
}
}
if(num<=0){
alert('请选择一条记录后点击');
}
else{
window.location=action+'?id='+id;
}
}
function updatePoJo(action){
var ids = document.getElementsByName("id");
var id = "";
var num = 0;
for(var i = 0;i<ids.length;i++){
if(ids[i].checked){
num++;
id=ids[i];
}
}
if(num>1){
alert("每次只能修改一条记录");
}
else if(num<1){
alert("请选择一条记录");
}
else if(num==1){
window.location=action+'?id='+id.value;
}
}
function openNewPage(action){
window.location=action;
}
</script>
</head>
<body>
<table id="tt"></table>
</body>
</html>
运行页面后控制台打印出来的Json:
[{name:"13",des:"13",id:"402880d12b0f715d012b0f71b9d50001"},{name:"123",des:"123",id:"402880d12b0f75ad012b0f75df2c0001"},{name:"345",des:"345",id:"402880d12b0f75ad012b0f77ada30002"},{name:"123",des:"123",id:"402880d12b1db77a012b1db86d9d0001"}]
请教各位高手,如何才能把Json输出到JSP页面并显示出来