页面:
<%@ 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的行号进行的,但我需要获得是编号啊????
解决方案 »
- org.hibernate.PropertyAccessException 各种报错 头大了求解
- spring配置jdbc事务管理插入数据失败
- JAVA开发环境都有哪些?哪个比较流行和简单易学啊?
- struts2的radio标签问题
- bpel调用web service?
- 初学者问题
- 想制作插件
- 请大家推荐一半 java设计模式 的好书!!
- 一个关于request.getCharacterEncoding()的问题,大家帮忙!
- Java的HttpClient类以POST方式提交数据,服务端收到后中文+符号乱码
- xfire客户端调用axis服务端,或者反过来
- java mail 发送邮件错误,javax.mail.AuthenticationFailedException: failed to connect
groupHeaders:[
{startColumnName: '开始列', numberOfColumns: 合并列数, titleText: '<em>title</em>'}}
]