JEECG弹出框提交表单

一、设备主页面(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,  
                    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',
        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=" 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;
    }
复制代码
原文地址:https://www.cnblogs.com/Jeely/p/12612645.html