easyui實現ValidateBox自定義驗證數據庫中是否存在重複字段

1.jsp頁面代碼

<script type="text/javascript">
	var isRepetition = false;
	$.extend($.fn.validatebox.defaults.rules, {
		myminLength : {
			validator : function(value, param) {
				var b = $('#pg').propertygrid('getData');
				//alert('hehe' + b.rows[0].value);

				$.ajax({
					tyep : "post",
					dataType : "text",
					async : false,//是否異步執行
					url : "testSystemAndJobRepetition.htm",
				    data:{systemName:b.rows[0].value,jobName:value},
					success : function(result) {
						isRepetition = (result === "true" ? true : false);
					},
					error : function(result) {
						isRepetition = false;
					}
				});
				//alert(isRepetition)
				return isRepetition;
			},
			message : 'Please enter at least {0} characters.'
		}
	});
</script>

2.java代碼

	@RequestMapping("/testSystemAndJobRepetition")
	public void testSystemAndJobRepetition(HttpServletRequest request,HttpServletResponse response) {
		String systemName = request.getParameter("systemName");
		String jobName = request.getParameter("jobName");
		logger.info("systemName:" + systemName + ",jobName:" + jobName);
		try {
			response.getWriter().write("" + !etlJobService.isRepetition(systemName, jobName));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

3.json文件

 

{"total":7,"rows":[
	{"name":"任務系統","value":"STG","group":"Settings","editor":{
	    "type":"combobox",
	    "options":{
	        "data":[{"value":"STG","text":"STG"},{"value":"ODS","text":"ODS"},{"value":"DMS","text":"DMS"},
	                {"value":"SRC","text":"SRC"},{"value":"OSI","text":"OSI"},{"value":"FDM","text":"FDM"},
	                {"value":"DTP","text":"DTP"},{"value":"APP","text":"APP"},{"value":"GDM","text":"GDM"},
	                {"value":"DW","text":"DW"},{"value":"DIM","text":"DIM"},{"value":"PUB","text":"PUB"}
	               ],
	        "panelHeight":"auto"
	    }
	  }
	},
	{"name":"任務名稱","value":"","group":"Settings","editor":"text"},
	{"name":"任務描述","value":"","group":"Settings","editor":"text"},
	{"name":"任務類型","value":"D","group":"Settings","editor":{
	    "type":"combobox",
	    "options":{
	        "data":[{"value":"D","text":"D"},{"value":"W","text":"W"},{"value":"M","text":"M"},{"value":"Q","text":"Q"},{"value":"I","text":"I"}],
	        "panelHeight":"auto"
	    }
	}},
	{"name":"任務頻次","value":"","group":"Settings","editor":"text"},
	{"name":"觸發任務","value":"","group":"Settings","editor":"text"},
	{"name":"依賴任務","value":"","group":"Settings","editor":"text"},
	{"name":"任務執行腳本","value":"","group":"Settings","editor":"text"},
	{"name":"時間觸發","value":"true","group":"Settings","editor":{
		"type":"checkbox",
		"options":{
			"on":true,
			"off":false
		}
	}},
	{"name":"開始時間","value":"","group":"Settings","editor":"text"},
	{"name":"啓動任務的機器 ","value":"","group":"Settings","editor":{
	    "type":"combobox",
	    "options":{
	        "data":[{"value":"1","text":"1"},{"value":"2","text":"2"},{"value":"3","text":"3"}],
	        "panelHeight":"auto"
	    }
	}},
	{"name":"任務創建人 ","value":"","group":"Settings","editor":"text"},
	{"name":"任務創建人 ","value":"","group":"Settings","editor":"text"},
	{"name":"name","value":"","group":"Settings","editor":{
	    "type":"validatebox",
	    "options":{
	        "validType":"myminLength[5]",
	        "invalidMessage":"this user is existed"
	    }
	}}
]}

4.運行結果


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章