Words don't say much, directly on the code
Formvalidator Authentication configuration in page head
<script type= "Text/javascript" >$ (document). Ready (function () {$.formvalidator.initconfig ({formID: "Form1", Theme: "Arrowsolidbox", Wideword:false,submitonce:true,onerror:function (msg, obj, errorlist) {$ ("#errorlist"). Empty (); $.map (errorlist, Function (msg) {$ ("#errorlist"). Append ("<li>" + msg + "</li>")}); alert (msg);}, Ajaxprompt: ' There is data being verified asynchronously, please wait a moment ... '}); $ ("#name"). Formvalidator ({tipid: "Nametip", OnShow: "Enter role name", Oncorrect: "Correct"}). Inputvalidator ({max:10,onerror: "Enter a maximum of 10 characters!") }). Regexvalidator ({regExp: "Notempty", DataType: "Enum", OnError: "Please enter role name"}). Ajaxvalidator ({url: "Sysroleaction_ Isrolenameajax.action ", type:" Post ", DataType:" HTML ", Data:{rolename:function () {return $ (" #name "). Val ()}, FilterName: "${name}"}, Success:function (data) {if (data== "true") {return false;} Else{return true;} }, Buttons: $ ("#button"), Error:function () {alert ("The server is not returning data, the server may be busy, try again"), OnError: "The role name already exists!", onwait: "Being diagonally Color name for legality check, please wait ... "}); $ (" #description "). FormvalidaTor ({tipid: "Descriptiontip", Empty:true,onshow: "Please enter your description", Oncorrect: "Congratulations, you lost the right"}). Inputvalidator ({max:20,onerror: "Enter up to 20 characters"}); </script>
Method of script validation in struts2 action
public void Isrolenameajax () throws IOException {/** text output stream print */printwriter out = Response.getwriter (); String roleName = Request.getparameter ("RoleName"); String filtername = Request.getparameter ("FilterName"); Boolean findbyrolename = Systemroleservice.findbyrolename ( Rolename,filtername); Out.print (findbyrolename); Out.flush (); Out.close ();}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Formvalidator to struts2 Ajax validation