EXTJS4.0.7开发积累
有从网络上搜索到的资源,也有自己开发中的总结,侵权告知删除!
HQL比较 | 在where子句中可以指定比较运算符:>,>=,<,<=,<>,其含义为大于,大于等于,小于,小于等于,不等于 |
HQL in | sb.append(" where m.id not in (:machinList)"); query.setParameterList("machinList",machineList); |
HQL start/limit | returnquery.setFirstResult(start).setMaxResults(limit).list(); |
HQL count | return((Number)query.uniqueResult()).intValue(); |
Sting2Timestamp | Timestamp ts =Timestamp.valueOf("1979-04-22 22:18:00"); System.out.println(ts); |
Json数据中有冒号以及其它符号的处理办法 | 当json数据中有冒号或其它符号时,解析会报错 错误数据格式如下{test:2011-11-1000:00:00,name:test\\]]\]\]\asfasdfasdf,age:28} 比较好的解决办法是将字符串中的key和value都加上""来包含 如下 {"test":"2011-11-1000:00:00","name":"test\\]]\]\]\asfasdfasdf","age":"28"} 在程序中需要将"进行转义 如下 {\"test\":\"2011-11-1000:00:00\",\"name\":\"test\\]]\]\]\asfasdfasdf\",\"age\":\"28\"} 这样解析的话,就OK啦
",eventEndTime:\""+request.getParameter("event_endTime")+"\""+ ",eventBeginTime:\""+request.getParameter("event_beginTime")+"\"" |
grid column renderer | In griddefine:{header:'Facility',dataIndex:'facility',renderer:facilityRenderer,width:50} Out grid define: function change(val){ if(val > 0){ return '<spanstyle="background:green;">' + val + '</span>'; }else if(val < 0){ return '<spanstyle="color:red;">' + val + '</span>'; } return val; } |
itemId | me.getDockedComponent('eventtopdockedItems').getComponent('event_endTime').getValue() Ext.getCmp('id');id是全局的,要避免重复,最好不使用 me.getComponent('itemId');itemId是局部的,在局部内不重复便可。me是父容器 |
actioncolumn(grid) | { xtype:'actioncolumn', width:50, // header: 'view', items: [{ action: 'edit', icon: 'images/cog_edit.png', // Use a URL in the icon config tooltip: 'Detail', handler: function(grid, rowIndex, colIndex) { this.fireEvent('itemclick',grid,rowIndex,colIndex); } }] } |
actioncolumn(controller) | machinelistactioncolumn': { itemclick: this.editMachine }, 不同于如下button的写法: 'machineeditbutton[action=save]': { click: this.updateMachine }, |
focus event | { xtype: 'timefield', name:'event_beginTime', itemId:'event_beginTime', format: 'H:i', hideLabel: true // value:'00:00' ,maxValue:new Date() // ,format: 'Y-m-d H:i:s' ,width: 60 ,listeners:{ 'focus':function(){ this.setMaxValue(new Date()); } } } |
tbar vs dockedItems | tbar: [ { xtype: 'button', text: 'Button 1' } ] dockedItems: [{ xtype: 'toolbar', dock: 'top', items: [ { xtype: 'button', text: 'Button 1' } ] }] dockedItems的好处:可以添加itemId,可以查找里面的items子组件 |
dockedItems包含: pagingtoolbar,toolbar | dockedItems: [{ xtype: 'pagingtoolbar', itemId:'eventbottomdockedItems', store : me.store, // same store GridPanel is using dock: 'bottom', displayInfo: true },{ xtype: 'toolbar', dock: 'top', items: [ { xtype: 'button', text: 'Button 1' } ] }] |
向后台请求CRUD外的操作 | changePassword:function(button){ if(button.up('window').down('form').getForm().isValid()){ var me = button.up('window'); button.up('window').down('form').getForm().doAction('submit',{ clientValidation:true, url:'changePassword.action', method:'post', success:function(form,action){ console.info('me:'+me.$className); Ext.Msg.alert('Change Success',action.result.message); }, failure:function(form,action){ me.show(); Ext.Msg.alert('Change Fail',action.result.message); } }); } } 【changePassword.action已经在struts.xml文件中配置好】 【这是window(包含form)上的一个按钮处理函数,发向后台的请求里面包括form里面输入字段,返回类似如下的json串:{success:false,message:"Change passwd failed:exception raised!"}】 |
返回详细的后台信息给前台 参照【向后台请求CRUD外的操作】条目 | 后台根据执行结果,设置json串里面的相应message内容(使用引号包裹,要不有空格或者其他特殊字符,无法解析json串),在前台的js里面使用callback/success/failure函数进行解析。 |
事务保护设置 | <tx:advice id="txAdvice" transaction-manager="myTransactionManager"> <tx:attributes> <tx:method name="change*" propagation="REQUIRED" /> 【事务保护,可以修改DB】 <!--hibernate4必须配置为开启事务 否则 getCurrentSession()获取不到--> <tx:method name="login*" propagation="REQUIRED" read-only="true" /> 【属于事务,但不可以修改DB】 <tx:method name="*" read-only="true" /> 【没有匹配change和login的,匹配此,不可以修改DB】 </tx:attributes> </tx:advice> 【不可以修改数据库的提示: 2013-09-23 23:16:57 [WARN]-[org.hibernate.engine.jdbc.spi.SqlExceptionHelper][line:143] SQL Error: 0, SQLState: S1009 2013-09-23 23:16:57 [ERROR]-[org.hibernate.engine.jdbc.spi.SqlExceptionHelper][line:144] Connection is read-only. Queries leading to data modification are not allowed 2013-09-23 23:16:57 [DEBUG]-[com.env.logman.server.service.impl.UserServiceImpl][line:48] user change password failed:admin 2013-09-23 23:16:57 [DEBUG]-[com.env.logman.server.service.impl.UserServiceImpl][line:49] org.hibernate.exception.GenericJDBCException: could not execute statement 】 |
异常处理策略及LOG/Action message配合 | DAO层不记录异常 Service处理DAO抛来的异常,并记录日志 Action处理前台Http类的异常,并记录日志(异常不输出到屏幕,写入日志文件,用户只需要知道操作是否成功,不成功是什么方向的原因) Service处理DAO(DB)的异常写log日志,Service不抛异常给action DAO不处理异常,直接抛出DB的异常给Service Service只返回是否成功的标识,不成功message标识为数据库异常;action捕捉的异常,message标记为http异常 |
DAO策略 | 愈是DB(DAO)的功能愈要原子单元化,在Service里可以把这些原子单元功能组装成一个完整的业务功能(一个完整的业务功能多半需要修改多个表结构) |
store.sync() | sync没有回调函数(callback/success/failure),可以使用如下的替代方法: Ext.define('DM.store.CommonSettingsStore',{ extend: 'Ext.data.Store', model: 'DM.model.CommonSettingsModel', autoLoad: false, proxy: {……} // , // onCreateRecords: function(records, operation, success) { // console.log("Create:" + records); // }, ,onUpdateRecords: function(records, operation, success) { if(success){ Ext.Msg.alert('Update Success',this.getProxy().getReader().rawData['message']); }else{ Ext.Msg.alert('Update Fail',this.getProxy().getReader().rawData['message']); } } // onDestroyRecords: function(records, operation, success) { // console.log("Destroy:" + records); // }, // // onProxyRead: function(records, operation, success) { // console.log("Read:" + records); // } }); |
Ext.Ajax.request | Ext.Ajax.request({ url:'findbyid.action', params:{ id:cell.getId() }, success: function(resp,opts) { var respText =Ext.util.JSON.decode(resp.responseText); name=respText.name; oid=respText.id; findbyid(graph,cell,oid,name); //Ext.Msg.alert('错误', respText.name+"====="+respText.id); }, failure:function(resp,opts) { var respText =Ext.util.JSON.decode(resp.responseText); Ext.Msg.alert('错误', respText.error); }
}); 注:extjs4.0.7中,Ext.util.JSON.decode需要去掉util |