一、設備主頁面(deviceMain.jsp)
<t:dgToolBar title="編輯設備" icon="icon-edit" url="deviceController.do?goDeviceDetail" funname="editMyDevice"></t:dgToolBar>
// 編輯管理的設備 function editMyDevice(title,url,gname){ var ids = ""; var rows = $("#" + gname).datagrid('getSelections'); if (rows.length == 1) { $.dialog.setting.zIndex = getzIndex(true); $.dialog.confirm('你確定編輯該數據嗎?', function(r) { if (r) { $.dialog({ content: 'url:'+url+"&ids="+rows[0].serial, lock : true, width:700, height:320, title:"編輯設備信息", opacity : 0.3, cache:false, cancelVal: '關閉', cancel: true, /*為true等價於function(){}*/ button:[{ name: '保存', callback: function(){ iframe = this.iframe.contentWindow;//獲取彈出層的iframe saveParam();//自定義保存數據方法 $("#"+gname).datagrid("reload"); $("#"+gname).datagrid('unselectAll'); return true;//阻止頁面關閉(默認為true不關閉) } }] }); } }); } else if (rows.length > 1) { tip("請選擇一條數據進行編輯"); } else { tip("請選擇需要編輯的數據"); } } /** * 自定義保存數據方法 * @param url * @param gridname */ function saveParam() { $("#formobj", iframe.document).form('submit', { onSubmit : function() { }, success : function(r) { msgdialog('操作成功!','success'); }, error : function(r) { msgdialog('操作異常!','error'); } });//UsersForm為Form表單id,提交表單 } /** * 操作結果提示語 * @param content:提示內容 * @param type:圖標類型 */ function msgdialog(content,type){ $.dialog({ content: content, title:'提示信息', icon: type+'.gif', titleIcon: 'lhgcore.gif', width:136, height:80, top: '98%', left:'98%', fixed: true }); }
二、設備彈出框編輯頁面(deviceEdit.jsp)
<body style="overflow-y: hidden" scroll="no"> <t:formvalid formid="formobj" layout="table" dialog="true" action="deviceController.do?doUpdateDevice"> <input id="serial" name="serial" type="hidden" value="${device.serial}"> <input id="phone" name="phone" type="hidden" value="${device.phone }"> <input id="smsflag" name="smsflag" type="hidden" value="${device.smsflag }"> <table style="width: 600px;" cellpadding="0" cellspacing="1" class="formtable"> <tr> <td align="right" width="25%" nowrap> <label class="Validform_label"> IP: </label> </td> <td class="value" width="85%"> <input id="nodeip" name="nodeip" class="inputxt" type="text" datatype="s1-200" value="${device.nodeip}"/> <span class="Validform_checktip"></span> </td> </tr> <tr> <td align="right"> <label class="Validform_label"> 主機名稱: </label> </td> <td class="value"> <input id="hostname" name="hostname" class="inputxt" type="text" value="${device.hostname}"/> </td> </tr> <tr> <td align="right"> <label class="Validform_label"> 類型: </label> </td> <td class="value"> <input id="type" name="type" class="inputxt" type="text" value="${device.type}"/> </td> </tr> </table> </t:formvalid> </body>
三、后台程序(DeviceController.java)
/** * 進入編輯頁面 * @param id * @param request * @return */ @RequestMapping(params="goDeviceDetail") public String goDeviceDetail(String ids, HttpServletRequest request) { String sql = "select * from device where Serial = " + ids; Device device= deviceService.excuteQuery(sql); device.setNodeip(device.getNodeip().trim()); device.setHostname(device.getHostname().trim()); device.setPhone(device.getPhone().trim()); device.setType(device.getType().trim()); device.setSmsflag(device.getSmsflag().trim()); request.setAttribute("device", device); return "device/deviceEdit"; }
/** * 更新設備信息 * * @return */ @RequestMapping(params = "doUpdateDevice") @ResponseBody public AjaxJson doUpdateDevice(Device device, HttpServletRequest request) { String message = "更新設備成功"; AjaxJson j = new AjaxJson(); String nodeip = device.getNodeip().trim(); String hostname = device.getHostname().trim(); String type = device.getType().trim(); String updateSybaseSql = "update device set NodeIP='" + nodeip + "', hostname='"+hostname+"', type='"+type+"' where Serial=" + device.getSerial(); int result = this.deviceService.excuteUpdate(updateSybaseSql); if(result != -1){ this.systemService.saveOrUpdate(device); try { DataSyncQueue.syncPhoneZrQueue.put("phone_zr"); //更新設備信息成功后,同步數據 } catch (InterruptedException e) { e.printStackTrace(); } } j.setMsg(message); return j; }