页面:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>首页</title>
<script src="${applicationScope.rootpath}js/jquery.js" type="text/javascript"></script>
<script src="${applicationScope.rootpath}js/jqgrid/js/jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="${applicationScope.rootpath}js/jqgrid/js/i18n/grid.locale-cn.js" type="text/javascript"></script>
<script src="${applicationScope.rootpath}js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="${applicationScope.rootpath}js/jqueryui/js/jquery-ui-1.8.6.custom.min.js" language="Javascript"></script>
<link href="${applicationScope.rootpath}js/jqgrid/css/ui.jqgrid.css" rel="stylesheet" type="text/css"/>
<link href="${applicationScope.rootpath}js/jqgrid/themes/redmond/jquery-ui-1.8.2.custom.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript">
var jq=jQuery.noConflict();
jq(document).ready(function(){
jq('#personList').trigger("reloadgrid");
jq("#personList").jqGrid({
url:'${applicationScope.rootpath}test/test_personList.action',
datatype: "json",
mtype: "POST",
height: 'auto',
colNames:['编号','姓名','年龄'],
colModel:[
{name:'ID',index:'ID',width:120,sorttype:"int",formatter:"int"},
{name:'NAME',index:'NAME',width:120,sorttype:"string",editable:true},
{name:'AGE',index:'AGE',width:120,sorttype:"int",formatter:"int",editable:true}
],
sortname:'ID',
sortorder:'asc',
viewrecords:true,
rowNum:10,
rowList:[10,20,30],
onSelectRow: function(ID){ //行点击事件
var rowData = jq("#personList").jqGrid("getRowData", ID);
var id=rowData.ID;
jq('#personList').jqGrid('editRow',ID,true);
},
editurl: "${applicationScope.rootpath}test/test_editPerson.action",//定义操作的路径
caption: "可编辑的表格",
pager: '#ppersonList', //定义翻页div
loadonce:true,
jsonReader: {
root:"rows", // 数据行(默认为:rows)
repeatitems : false // 设置成false,在后台设置值的时候,可以乱序。且并非每个值都得设
}
});
//设置底部的按钮状态
jq("#personList").jqGrid('navGrid',"#ppersonList",{edit:true,add:true,del:true,search:true,view:false});
}); </script>
</head>
<body>
操作表<br/>
<table id="personList"></table>
<div id="ppersonList"></div>
<!--
<input type="button" id="btnAdd" value="Add"/>
<input type="button" id="btnEdit" value="Edit"/>
<input type="button" id="btnDel" value="Del"/>
-->
</body>
</html>
action:
public String personList(){
List<Person> personList=this.service.findAll();
JSONObject obj = new JSONObject();
JSONArray lineitemArray = new JSONArray();
for(Person p:personList){
JSONObject o = new JSONObject();
o.put("ID",p.getId());
o.put("NAME",p.getName());
o.put("AGE",p.getAge());
o.put("PID",p.getId());
lineitemArray.add(o);
}
obj.put("rows", lineitemArray); //具体的Table显示内容
String jsonStr = JSONObject.fromObject(obj).toString();
setTextAjax(jsonStr);
return HTML;
}
public String editPerson(){
System.out.println(id+"+++++++"+oper);
if(oper != null && oper.equals("edit")){ //修改
Person p=this.service.findById(this.id);
p.setName(this.NAME);
p.setAge(this.AGE);
this.service.update(p);
}
if(oper != null && oper.equals("add")){ //添加
Person p=new Person();
p.setName(this.NAME);
p.setAge(this.AGE);
this.service.add(p);
}
if(oper != null && oper.equals("del")){ //删除
Person p=this.service.findById(this.id);
this.service.del(p);
}
return personList();
}
修改和删除是按table的行号进行的,但我需要获得是编号啊????
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>首页</title>
<script src="${applicationScope.rootpath}js/jquery.js" type="text/javascript"></script>
<script src="${applicationScope.rootpath}js/jqgrid/js/jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="${applicationScope.rootpath}js/jqgrid/js/i18n/grid.locale-cn.js" type="text/javascript"></script>
<script src="${applicationScope.rootpath}js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="${applicationScope.rootpath}js/jqueryui/js/jquery-ui-1.8.6.custom.min.js" language="Javascript"></script>
<link href="${applicationScope.rootpath}js/jqgrid/css/ui.jqgrid.css" rel="stylesheet" type="text/css"/>
<link href="${applicationScope.rootpath}js/jqgrid/themes/redmond/jquery-ui-1.8.2.custom.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript">
var jq=jQuery.noConflict();
jq(document).ready(function(){
jq('#personList').trigger("reloadgrid");
jq("#personList").jqGrid({
url:'${applicationScope.rootpath}test/test_personList.action',
datatype: "json",
mtype: "POST",
height: 'auto',
colNames:['编号','姓名','年龄'],
colModel:[
{name:'ID',index:'ID',width:120,sorttype:"int",formatter:"int"},
{name:'NAME',index:'NAME',width:120,sorttype:"string",editable:true},
{name:'AGE',index:'AGE',width:120,sorttype:"int",formatter:"int",editable:true}
],
sortname:'ID',
sortorder:'asc',
viewrecords:true,
rowNum:10,
rowList:[10,20,30],
onSelectRow: function(ID){ //行点击事件
var rowData = jq("#personList").jqGrid("getRowData", ID);
var id=rowData.ID;
jq('#personList').jqGrid('editRow',ID,true);
},
editurl: "${applicationScope.rootpath}test/test_editPerson.action",//定义操作的路径
caption: "可编辑的表格",
pager: '#ppersonList', //定义翻页div
loadonce:true,
jsonReader: {
root:"rows", // 数据行(默认为:rows)
repeatitems : false // 设置成false,在后台设置值的时候,可以乱序。且并非每个值都得设
}
});
//设置底部的按钮状态
jq("#personList").jqGrid('navGrid',"#ppersonList",{edit:true,add:true,del:true,search:true,view:false});
}); </script>
</head>
<body>
操作表<br/>
<table id="personList"></table>
<div id="ppersonList"></div>
<!--
<input type="button" id="btnAdd" value="Add"/>
<input type="button" id="btnEdit" value="Edit"/>
<input type="button" id="btnDel" value="Del"/>
-->
</body>
</html>
action:
public String personList(){
List<Person> personList=this.service.findAll();
JSONObject obj = new JSONObject();
JSONArray lineitemArray = new JSONArray();
for(Person p:personList){
JSONObject o = new JSONObject();
o.put("ID",p.getId());
o.put("NAME",p.getName());
o.put("AGE",p.getAge());
o.put("PID",p.getId());
lineitemArray.add(o);
}
obj.put("rows", lineitemArray); //具体的Table显示内容
String jsonStr = JSONObject.fromObject(obj).toString();
setTextAjax(jsonStr);
return HTML;
}
public String editPerson(){
System.out.println(id+"+++++++"+oper);
if(oper != null && oper.equals("edit")){ //修改
Person p=this.service.findById(this.id);
p.setName(this.NAME);
p.setAge(this.AGE);
this.service.update(p);
}
if(oper != null && oper.equals("add")){ //添加
Person p=new Person();
p.setName(this.NAME);
p.setAge(this.AGE);
this.service.add(p);
}
if(oper != null && oper.equals("del")){ //删除
Person p=this.service.findById(this.id);
this.service.del(p);
}
return personList();
}
修改和删除是按table的行号进行的,但我需要获得是编号啊????
解决方案 »
- 关于hibernate session疑问
- 关于hibernate映射oracle的date类型的问题
- 纯jsp
- 困惑
- [求助]用jwsdp2.0生成的web service的wsdl文件存放在什么地方?郁闷啊,高手指教
- 用ibatis感觉程序运行速度慢,不知道大家有没有感觉,应该如何解决呢?
- Struts遇到java.lang.NullPointerException错误了!救命
- 跪求在 J2EE 1.3 中如何配置 Cloudscape 数据库的可视化工具 Cloudview 的方法
- 在websphere上部署好的.ear文件,可以在jboss中运行,为什么不能在websphere上运行?
- jsf hibernate spring框架遇到问题
- xfire客户端调用axis服务端,或者反过来
- java mail 发送邮件错误,javax.mail.AuthenticationFailedException: failed to connect
groupHeaders:[
{startColumnName: '开始列', numberOfColumns: 合并列数, titleText: '<em>title</em>'}}
]