EXTJS4.0.7开发积累
有从网络上搜索到的资源,也有自己开发中的总结,侵权告知删除!
jsp 中 request.getHeader() 相关详细 | jsp 中 request.getHeader() 相关详细 System.out.println("Protocol: " +request.getProtocol()); System.out.println("Scheme: " +request.getScheme()); System.out.println("Server Name: " +request.getServerName() ); //获得服务器的名字 System.out.println("Server Port: " +request.getServerPort()); //获得服务器的端口号 System.out.println("rotocol: " +request.getProtocol()); System.out.println("Server Info: " +getServletConfig().getServletContext().getServerInfo()); System.out.println("Remote Addr: " + request.getRemoteAddr());/获得客户端的ip地址 System.out.println("Remote Host: " +request.getRemoteHost()); //获得客户端电脑的名字,若失败,则返回客户端电脑的ip地址 System.out.println("Character Encoding: " +request.getCharacterEncoding()); System.out.println("Content Length: " + request.getContentLength()); System.out.println("Content Type: "+request.getContentType()); System.out.println("Auth Type: " +request.getAuthType()); System.out.println("HTTP Method: " +request.getMethod()); //获得客户端向服务器端传送数据的方法有get、post、put等类型 System.out.println("ath Info: " +request.getPathInfo()); System.out.println("ath Trans: " +request.getPathTranslated()); System.out.println("Query String: " +request.getQueryString()); System.out.println("Remote User: " +request.getRemoteUser()); System.out.println("Session Id: " +request.getRequestedSessionId()); System.out.println("Request URI: " +request.getRequestURI());//获得发出请求字符串的客户端地址 System.out.println("Servlet Path: " +request.getServletPath()); //获得客户端所请求的脚本文件的文件路径 System.out.println(request.getHeaderNames()); //返回所有request header的名字,结果集是一个enumeration(枚举)类的实例 System.out.println("Accept: " +request.getHeader("Accept")); System.out.println("Host: " +request.getHeader("Host")); System.out.println("Referer : " +request.getHeader("Referer")); System.out.println("Accept-Language : " +request.getHeader("Accept-Language")); System.out.println("Accept-Encoding : " + request.getHeader("Accept-Encoding")); System.out.println("User-Agent : " +request.getHeader("User-Agent")); //返回客户端浏览器的版本号、类型 System.out.println("Connection : " +request.getHeader("Connection")); System.out.println("Cookie : " +request.getHeader("Cookie")); System.out.println("Created : " +session.getCreationTime()); System.out.println("LastAccessed :" +session.getLastAccessedTime()); |
为displayfield添加click事件 | { xtype: 'displayfield', fieldLabel: '在线用户', labelWidth:60, name: 'visitor_score', value: '11', width:100, listeners: { afterrender: function(component) { component.getEl().on('click', function() { alert('display field was clicked!') }); } } } |
把Long型毫秒转化成日期 | /** * transfer millSec to date+time * @param dateFormat(format:MM/ dd/yyyy HH:mm:ss)|| yyyy-MM-dd HH:mm:ss * @param millSec * @return */ public static String transferLongToDate(String dateFormat,Long millSec){ SimpleDateFormat sdf = new SimpleDateFormat(dateFormat); Date date= new Date(millSec); return sdf.format(date); } } |
boolean值在grid上的显示 不使用render | xtype: 'booleancolumn', text: 'Enable', trueText: 'Yes', falseText: 'No', dataIndex: 'status' |
select new com.clsss could not instantiate class fromtuple | 于是进代码跟踪,最终发现是在构造一个vo的时候select new com.xxxvo(doc.id asid,doc.parentFrId as pid,doc.commentEnabled as commentEnabled), 入参有一个值是null,但vo中定义的是boolean.把这个入参转化成布尔值后,错误消除。 究其原因是在sqlserver下修改过原表中字段的默认值,但是只对新数据有效,原来的数据不能修改为新默认值,还保持了原来的null,再次对其应用update后才修改了。 后续有增加boolean字段的时候,不仅进行字段的增加操作,还需要进行该字段值的update操作。 |
sql查询获得Map List | service: StringBuffer sql = new StringBuffer(100); sql.append("select "+group_value_col+" as "+group_value_col); sql.append(","+group_display_col+" as "+group_display_col); sql.append(" from "+group_table); return jdbcDAO.getMapList(sql.toString()); DAO: public List<?> getMapList(String sql){ return jdbcTemplate.queryForList(sql); } action: List<?> groupItemList=miService.getGroupItem(group_table, group_value_col, group_display_col); JSONArray array = JSONArray.fromObject(groupItemList); this.setJsonString("{success:true,list:" + array.toString() + "}"); 界面返回: {success:true,list:[{"LogicSys_1_Tbl_3_col_7":1,"LogicSys_1_Tbl_3_col_8":"usertype1"},{"LogicSys_1_Tbl_3_col_7":2,"LogicSys_1_Tbl_3_col_8":"usertype2"},{"LogicSys_1_Tbl_3_col_7":3,"LogicSys_1_Tbl_3_col_8":"usertype3"},{"LogicSys_1_Tbl_3_col_7":4,"LogicSys_1_Tbl_3_col_8":"usertype4"},{"LogicSys_1_Tbl_3_col_7":5,"LogicSys_1_Tbl_3_col_8":"usertype5"}]} |
eval('itemList[key].'+value_col) 变量问题 | 如果value_col是变量,采用此种方式:eval('itemList[key].'+value_col) itemList[key].value_col:这里的value_col当作字符串来处理 var itemId_tmp_edit=pageblockList[key].db_col_name; addwindow.down('#'+itemId_tmp_edit).setValue(rec.get(pageblockList[key].db_col_name)); |
Ext.Ajax.request({}) 异步执行数据传输问题 异步执行与实时执行有较大的差别 | if(pageblockList[key].compts_xtype=='radiogroup'){ var pageblockList_tmp=pageblockList[key]; Ext.Ajax.request({}); } 在Ext.Ajax.request({});中,因为是异步执行,可能取不到pageblockList[key]里面的值,这时创建一个临时变量进行保存: var pageblockList_tmp=pageblockList[key]; |
datefield注意 maxValue设置 eval | view.down('form').add({ ,maxValue:Ext.Date.add(new Date(),Ext.Date.DAY, eval(pageblockList[key].compts_maxValue)) }); eval(pageblockList[key].compts_maxValue))没有eval不行啊 console.info('maxValue:'+pageblockList[key].compts_maxValue);好像已经自动执行了eval了 |
extjs 怎么取得系统时间 | ExtJs取系统时间就和JS一样的呀,方法如下: var myDate = newDate(); // 得到系统日期 然后就可以得到时间了: myDate.getYear(); //获取当前年份(2位) myDate.getFullYear(); //获取完整的年份(4位,1970-????) myDate.getMonth(); //获取当前月份(0-11,0代表1月) myDate.getDate(); //获取当前日(1-31) myDate.getHours(); //获取当前小时数(0-23) myDate.getMinutes(); //获取当前分钟数(0-59) myDate.getSeconds(); //获取当前秒数(0-59) myDate.getMilliseconds(); //获取当前毫秒数(0-999) |
combobox控件创建时设值 afterrender方法中 | this.down('form').add( { xtype:'combobox', itemId: 'compts_allowBlank', fieldLabel:'输入值允许空', emptyText:'选择...', triggerAction:'all', allowBlank: false ,store: trueorfalse ,forceSelection: true ,editable: false ,queryMode: 'local' ,displayField: 'name' ,valueField: 'abbr' ,value:eval(this.parentwindow.down('#compts_allowBlank').getValue()) } ); eval(this.parentwindow.down('#compts_allowBlank').getValue())必须添加有eval才能识别出来 |
mysql的时间戳、日期、时间 | mysql的时间戳、日期、时间保存方式(id1:timestamp/id2:datetime) mysql> insert into t8(id,id1,id2,mydate,mytime) values (2,'2014-12-30 22:27:40. 0','2014-12-3022:27:40.0','2014-12-31','22:30:00'); timestamp有时间范围的限制,目前1970年之前月2037年之后的时间都不能使用timestamp. 而dateTime 支持的范围是'1000-01-01 00:00:00'到'9999-12-31 23:59:59' |
extjs中文化问题 | 注意这个文件,导致中文化:ext407/locale/ext-lang-zh_CN.js 时间控件中会把am/pm翻译成中文,然后就导致校验无法通过 |
Ext.form.DateField | datefield就有datepicker的功能,hideTrigger: true会把后面的picker功能隐藏 format: 'Y/m/d':显示2014/12/31 format: 'Y-m-d':显示2014-12-31 value:new Date():显示今天的默认值 |
Ext.form.TimeField | format:显示格式,默认为“g:i A”。一般使用“H:i:s” H:带前缀0的24小时 i:带前缀0的分钟 s:带前缀0的秒 format:'H:i:s'可以显示24小时制式的日期格式,而不是12小时加AM/PM制式的格式 |
store | // destroy the store if the gridis destroyed autoDestroy: true, |
StringBuffer 支持类似String的方法 | sb_cols.substring(0,sb_cols.length()-1) |
用户自定义校验改进 (重复值校验) | 老方法一般是在form里面添加hidden控件 { xtype:'hidden', itemId:'validation_hidden', name:'userNameValidation', value:'false' } 但该hidden值并不需要传送到后台保存,只是页面校验使用,为避免hidden向后台提交,影响判断,可改进为如下: 创建一个form属性user_validation:false,用户校验方法执行的时候根据校验结果设置该值true或者false, me.up('form').user_validation=false; me.up('form').user_validation=true; 然后在提交前检查该值,true允许提交,false不允许提交 if(this.up('form').user_validation==true){ if(this.up('form').getForm().isValid()){ |
MySql 主键自动增长 | mysql> create table user( -> id integer primary key, -> firstname varchar(200) not null, -> lastname varchar(200) not null, -> age integer -> ); Query OK, 0 rows affected (0.46sec) mysql> alter table user modify id integer auto_increment ; 或者创建表的时候就进行指定,如此插入数据的时候就可以不管id值: create table user_test( id integer primary key auto_increment, firstname varchar(200) ); insert into user_test (firstname)values('klt3'); |
回调函数(callback) | Ext.MessageBox.confirm('Remove Confirm', 'are you sure to remove this?', callBack); function callBack(id) { if(id=='yes'){} }; |