jquery.validationEngine+ajax验证

利用jquery.validationEngine ajax验证后台id是否已存在

前台jquery validation框架验证

jsp:

<link rel="stylesheet" type="text/css" href="<%=path%>/js/css/validationEngine.jquery.css"/>

<script type="text/javascript" src="<%=path%>/js/jquery/jquery-1.4.2.min.js"></script>

<script type="text/javascript" src="<%=path%>/js/validation/jquery.validationEngine-cn.js"></script>

<script type="text/javascript" src="<%=path%>/js/validation/jquery.validationEngine.js"></script>



 <input  type="text" name="item.entry" id="item_entry" class="validate[required,custom[onlyNumber],ajax[ajaxItemNoCall],length[0,4]] text-input" size="10"/></td>

 

jquery.validationEngine-cn.js

                "ajaxItemNoCall": {

	                "url": "validateItemNo",

				    "alertText": "* ID已被使用",

				    "alertTextOk": "*ID可以使用",

				    "alertTextLoad": "* 检查中, 请稍候..."

	            }

 

ItemAction.java

 

@Action(results = {@Result(type="json")}, params = { "excludeProperties", "validateReturn"}, value="validateItemNo")

	public String validateItemNo() throws Exception{

		ActionContext ct = ActionContext.getContext();

		HttpServletRequest request= 

			(HttpServletRequest)ct.get(ServletActionContext. HTTP_REQUEST ); 

		String validateId = request.getParameter("fieldId");

		String validateValue = request.getParameter("fieldValue");

		int valiValue = Integer.parseInt(validateValue);

		   

			item = itemService.findItemById(valiValue);

				if(item.getEntry() != valiValue){

					validateReturn[0] = validateId;

					validateReturn[1] = true;

					validateReturn[2] = "可以使用";

				}else {

					validateReturn[0] = validateId;

					validateReturn[1] = false;

					validateReturn[2] = "在指定ID已经存在";

				}

		return "success";

	}

你可能感兴趣的:(jquery.validationEngine+ajax验证)