Hibernate + Spring + Struts 2 + ExtJS CRUD 기능 개발 (3)
18607 단어 JavaScriptspringjsonHibernateext
spring, :
<bean id="LevelService" parent="baseTransactionProxy">
<property name="target">
<bean class="privilege.service.LevelService">
<property name="dao">
<bean class="privilege.dao.LevelDAO">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</property>
</bean>
</property>
</bean>
<bean id="LevelAction" class="privilege.action.LevelAction">
<property name="levelService" ref="LevelService" />
</bean>
struts.xml:
:
<action name="AddLevel" class="LevelAction" method="persistLevel">
<result>/resource/json_struts2.jsp</result>
</action>
:
<action name="LoadLevel" class="LevelAction" method="findLevelById">
<result>/resource/json_struts2.jsp</result>
</action>
:
<action name="LevelAjaxJsonData" class="LevelAction" method="jsonExecute">
<result>/resource/json_struts2.jsp</result>
</action>
json_struts2.jsp :
, JSON , :
<s:property> escape false, true, JSON 。
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><%@ taglib prefix="s" uri="/struts-tags"%>
<s:property value="jsonString" escape="false" />
Level.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> </title>
javascript :
<link rel="stylesheet" type="text/css" href="/my/resource/ext2.0/resources/css/ext-all.css" />
<link rel="stylesheet" type="text/css" href="/my/resource/ext2.0/init.css" />
<script src="/my/resource/ext2.0/adapter/ext/ext-base.js" type="text/javascript"></script>
<script src="/my/resource/ext2.0/ext-core.js" type="text/javascript"></script>
<script src="/my/resource/ext2.0/ext-all.js" type="text/javascript"></script>
Init.jsp javascript , , jsp , Extjs examples/examples.js :
<script src="/my/resource/ext2.0/init.jsp" type="text/javascript"></script>
<script src="/my/resource/ext2.0/source/locale/ext-lang-zh_CN.js" type="text/javascript"></script>
Level.js js:
<SCRIPT type="text/javascript" src="Level.js"></SCRIPT>
<SCRIPT type="text/javascript">
Ext.BLANK_IMAGE_URL = /my/resource/ext2.0/resources/images/default/s.gif';
</SCRIPT>
<STYLE type="text/css">
.ss {
text-align: left;;
}
.icon-grid {
background-image: url(grid.png) !important;
}
.add {
background-image: url(new.png) !important;
}
.edit {
background-image: url(edit.png) !important;
}
.remove {
background-image: url(del.png) !important;
}
</STYLE>
</head>
<body class="x-vista">
<div id="topic-grid"></div>
<div id="topic-win" class="x-hidden">
<div class="x-window-header">Hello Dialog</div>
<div id="topic-tabs"></div>
</div>
</body>
</html>
Level.js :
myinit();//
Ext.onReady(function() {
Ext.QuickTips.init();
var newFormWin;
var form1;
// JsonReader , , grid
var _jsonReader = new Ext.data.JsonReader( {
root : 'list',
totalProperty : 'totalCount',
id : 'levelid',
successProperty : '@success'
}, [ {
name : 'levelid',
mapping : 'levelid',
type : 'int'
}, {
name : 'levelname',
mapping : 'levelname'
}, {
name : 'description',
mapping : 'description'
}]);
// Store , proxy , url : 'LevelAjaxJsonData.action' , new Ext.data.HttpProxy, Ext.data.ScriptTagProxy
var ds = new Ext.data.Store( {
proxy : new Ext.data.HttpProxy( {
url : 'LevelAjaxJsonData.action'
}),
//
reader : _jsonReader
});
ds.setDefaultSort('levelid', 'desc');//
// ColumnModel , grid
var cm = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
id : 'levelid',
header : ' ',
dataIndex : 'levelid',
width : 40
}, {
header : " ",
dataIndex : 'levelname',
width : 50,
sortable : true,
locked : false
}, {
header : " ",
dataIndex : 'description',
width : 100
}]);
// by default columns are sortable
cm.defaultSortable = true;
// GridPanel
var grid = new Ext.grid.GridPanel( {
// var grid = new Ext.grid.EditorGridPanel( {
collapsible : true,//
animCollapse : false,//
title : ' ',
iconCls : 'icon-grid',
store : ds,
cm : cm,
renderTo : 'topic-grid',
viewConfig : {
forceFit : true
},
/*
* // buttons : [ { text : ' ' }, { text : ' ' }],
* buttonAlign : 'center',//
*
*/
//
bbar : new Ext.PagingToolbar( {
pageSize : 30,
store : ds,
displayInfo : true,
displayMsg : ' {0}-{1} / {2} ',
emptyMsg : " 。",
items : ['-', {
pressed : true,
enableToggle : true,
text : ' ',
cls : 'x-btn-text-icon details',
toggleHandler : ptb_bt1
}]
}),
//
tbar : [ {
id : 'New1',
text : ' ',
tooltip : ' ',
iconCls : 'add',
handler : function() {
ptb_bt1();
}
}, '-', {
text : ' ',
tooltip : ' ',
iconCls : 'edit',
handler : function() {
ptb_bt2();
}
}, '-', {
text : ' ',
tooltip : ' ',
iconCls : 'remove',
handler : function() {
ptb_bt3();
}
}],
width : 700,
height : 400,
frame : true,
loadMask : true,//
autoShow : true
});
//
ds.load( {
params : {
start : 0,//
limit : 30,// ,
forumId : 4
}
});
grid.render();
// ,
grid.on("rowdblclick", function(grid) {
loadFormData(grid);
});
//
var loadFormData = function(grid) {
var _record = grid.getSelectionModel().getSelected();
if (!_record) {//
Ext.example.msg(' ', ' !');
} else {
myFormWin();
form1.form.load( {
url : 'LoadLevel.action?level.levelid='
+ _record.get('levelid'),
waitMsg : ' ...',
failure : function() {
Ext.example.msg(' ', ' ');
},
success : function() {
Ext.example.msg(' ', ' !');
}
});
}
}
// --
var ptb_bt1 = function() {
myFormWin();
};
//
var ptb_bt2 = function() {
loadFormData(grid);
};
//
var ptb_bt3 = function() {
var _record = grid.getSelectionModel().getSelected();
if (_record) {//
Ext.MessageBox.confirm(' ', ' ?', function(btn) {
if (btn == "yes") {
var m = grid.getSelections();//
var jsonData = "";//
for (var i = 0, len = m.length;i < len; i++) {
var ss = m[i].get("levelid");
if (i == 0) {
jsonData = jsonData + ss;
} else {
jsonData = jsonData + "," + ss;
}
ds.remove(m[i]);
}
ds.load( {
params : {
start : 0,
limit : 30,
delData : jsonData// , JSON , , ID ,
}
});
// Ext.example.msg('--- ---', ' ');
}
});
} else {
Ext.example.msg(' ', ' !');
}
};
// form_win Window , 。
var myFormWin = function() {
// create the window on the first click and reuse on subsequent
// clicks
if (!newFormWin) {
newFormWin = new Ext.Window( {
el : 'topic-win',
layout : 'fit',
width : 400,
height : 300,
closeAction : 'hide',
plain : true,
title : ' ',
items : form1,
reader : _jsonReader
});
}
newFormWin.show('New1');
}
// Form JsonReader ,
var _jsonFormReader = new Ext.data.JsonReader( {
root : 'list',
totalProperty : 'totalCount',
id : 'levelid',
successProperty : '@success'
}, [ {
name : 'level.levelid',
mapping : 'levelid',
type : 'int'
}, {
name : 'level.levelname',
mapping : 'levelname'
}, {
name : 'level.description',
mapping : 'description'
}]);
//
form1 = new Ext.FormPanel( {
// collapsible : true,//
labelWidth : 75, // label settings here cascade unless overridden
url : 'AddLevel.action',
frame : true,
title : ' ',
bodyStyle : 'padding:5px 5px 0',
width : 350,
waitMsgTarget : true,
reader : _jsonFormReader,
defaults : {
width : 230
},
defaultType : 'textfield',
items : [ {
fieldLabel : ' ID',
name : 'level.levelid',
allowBlank : false
}, {
fieldLabel : ' ',
name : 'level.levelname',
allowBlank : false
}, new Ext.form.TextArea( {
fieldLabel : ' ',
name : 'level.description',
growMin : 234
})],
buttons : [ {
text : ' ',
disabled : false,
handler : function() {
if (form1.form.isValid()) {
form1.form.submit( {
url : 'AddLevel.action',
success : function(from, action) {
Ext.example.msg(' ', ' !');
ds.load( {
params : {
start : 0,
limit : 30,
forumId : 4
}
});
},
failure : function(form, action) {
Ext.example.msg(' ', ' !');
},
waitMsg : ' , ...'
});
dialog.hide();
} else {
Ext.Msg.alert(' ', ' !');
}
}
}, {
text : ' ',
handler : function() {
newFormWin.hide();
}
}]
});
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
기초 정리 - 1문자 (String) 숫자 (Number) 불린 (Boolean) null undefined 심볼 (Symbol) 큰정수 (BigInt) 따옴표로 묶어 있어야 함 Not-A-Number - 숫자 데이터 / 숫자로 표...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.