Struts2 Jquery Grid
i have used Struts2 Jquery Grid and my grid is having some Rows in which there are some usernames ,开发者_JS百科 passwords and so on, if i am adding any duplicate username it is allowing me to add the duplicate username, i want to know if there is a way which will warn me that there is a user with the same username.
I had the same requirement, but there's no direct way of doing it, but I found something useful looking in the source code of the plugin and here is what I did.
GRID
navigatorAddOptions="{
reloadAfterSubmit:true,
afterSubmit:function(response,postdata){
return isError(response.responseText);
}
}"
javascript
<script type="text/javascript">
function isError(text){
// document.getElementById("errorpara").innerHTML=text;
if(text.indexOf('ERROR')>=0){
return [false,text];
}
return [true,''];
}
</script>
in struts.xml
<result name="error">/x.jsp</result>
x.jsp
<%@taglib prefix="s" uri="/struts-tags" %>
<s:actionerror/>
<s:actionmessage/>
<s:fielderror/>
in the action
addActionError("ERROR: Username already exists!");
return ERROR;
So here the add/edit dialog box of grid shows up the error.
No. This is a business requirement you have and you need to incorporate it yourself. You could have a constraint at table level and catch the particular constraint violation exception, to be shown on screen any way you desire.
精彩评论