Ext.require([ '*' ]); Ext.onReady(function() {//onReady()函数在页面注册多个函数,依次执行 Ext.QuickTips.init(); Ext.state.Manager.setProvider(Ext.create('Ext.state.CookieProvider')); Ext.state.Manager.setProvider(Ext .create('Ext.state.CookieProvider')); //表单组合控件 var form = new Ext.form.FormPanel({ labelAlign : 'right', autoScroll : true, labelWidth : 50, width : 600, // title: 'form', frame : true, //reader:reader, //standardSubmit:true, //url:'servlet/AddQueServlet', items : [ { layout : 'form', items : [ { //columnWidth:.7, xtype : 'fieldset', layout : 'form', checkboxToggle : true,//折叠fieldset title : '文字输入', autoHeight : true, defaults : { width : 400 }, defaultType : 'textfield', items : [ { fieldLabel : '题目', name : 'head', allowBlank : false }, { xtype : 'htmleditor', fieldLabel : '题目备注及说明', id : 'editor', anchor : '98%', name : 'remarks', fontFamilies: ["宋体", "隶书", "黑体","Times New Roman"] }, { xtype : 'hidden', name : 'hidden' } ] }, { //columnWidth:.3, xtype : 'fieldset', checkboxToggle : true, title : '数据验证', autoHeight : true, defaultType : 'checkbox', hideLabels : true, layout : 'column', name:'checkValue', //style: 'margin-left:10px;', //bodyStyle: 'margin-left:20px;', items : [ { boxLabel : '必填', columnWidth : .125, name : 'check', inputValue : '1', checked : true, width : 'auto' }, { boxLabel : '手机号码', columnWidth : .125, name : 'check', inputValue : '2', //checked: true, width : 'auto' }, { boxLabel : '邮编', columnWidth : .125, name : 'check', inputValue : '3', width : 'auto' }, { boxLabel : '身份证号', columnWidth : .125, name : 'check', inputValue : '4', width : 'auto' }, { boxLabel : '日期', columnWidth : .125, name : 'check', inputValue : '5', width : 'auto' }, { boxLabel : 'Email', columnWidth : .125, name : 'check', inputValue : '6', width : 'auto' }, { boxLabel : '必答题', columnWidth : .25, name : 'check', inputValue : '7', width : 'auto' } ] }, { xtype : 'fieldset', checkboxToggle : true, title : '选项(每行一个)', autoHeight : true, defaultType : 'textarea', hideLabels : true, layout:'form', //style: 'margin-left:10px;', //bodyStyle: 'margin-left:20px;', items : [ { xtype:'textfield', fieldLabel : '输入选项个数', name : 'number' },{ width : 400, grow : true, name : 'options', //allowBlank : false, emptyText : '输入选项', maxLength : 10, minLength : 2 } ] }, { xtype : 'fieldset', //checkboxToggle:true, title : '选项排列', autoHeight : true, defaultType : 'radio', hideLabels : true, layout : 'column', //style: 'margin-left:10px;', //bodyStyle: 'margin-left:20px;', items : [ { boxLabel : '横向', name : 'rank', inputValue : '1', //checked: true, width : 'auto' }, { boxLabel : '竖向', name : 'rank', inputValue : '2', checked : true, width : 'auto' } ] } ] } ], buttons: [{ text: '保存', handler: function(){ //此处可以用myFormPanel.getForm()和myFormPanel.form两种方法获得表单对象. form.getForm().submit({//提交表单数据 url: 'servlet/AddQueServlet',//处理页面,注意返回内容格式的正确性 method: 'post', success: function(form, action) {//保存成功 Ext.Msg.alert('保存成功', action.result.msg); }, failure: function(form, action) {//保存失败 Ext.Msg.alert('保存失败', action.result.msg); } }) ; } },{ text: '重置', handler: function(){ form.form.reset() ;//重置表单 } }] }); form.getForm().load({ url: 'DesignQuestions/ShowQueByIdJson.jsp', params: { id: 'load' }, failure: function(form, action) { Ext.Msg.alert("Load failed", action.result.errorMessage); }, success:function(form, action) { Ext.Msg.alert("Load success", action.result.errorMessage); } }); var viewport = Ext.create('Ext.Viewport', { id : 'Center_left', layout : 'fit', autoScroll : true, items : [form] }); form.render("form"); });
<%
String qID=request.getParameter("q_id");
session.setAttribute("q_id", qID);
//System.out.print(qID);
%>[/code]
这个表单我想要自动填充,从ShowQueByIdJson.jsp获取值:
[code="java"]<%int q_id = Integer.parseInt((String)session.getAttribute("q_id"));// 获得页面传递的参数
Questions q = new Questions();
QuestionsDao questionDao = new QuestionsDaoImpl();
q = questionDao.findQuestionsById(q_id);// 调用实现类中根据id查询的方法 %>
<%
String id = request.getParameter("id") ;
if(id!=null &&"load".equals(id)){
%>
{
success: true,
data: {
head: "${q.q_head }",
remarks: "${q.q_remarks }",
number:"${q.q_number }",
options: ${q.q_body }"
}
}
<%
}else{
%>
{
success: false,
msg: "数据载入错误"
}
<%
}
%> [/code]
问题来啦!session范围是一个会话,这个q_id传不到ShowQueByIdJson.jsp,所以查不到数据写进JSON字符串,怎样才能达到:点击修改,跳转到表单的页面能够把应该的信息都填充的效果?