ActionError- It is used to show error message (means -ve sense message) to users.
ActionMessage- It is used to show informative message (means +ve sense message) to users.
FieldError- It is used to show field error (validation error) to users.
home.jsp
In this page we will check for actionmessage, actionerror and field error .If any of these exist then errorHandling.jsp page will display in dialog box.
<s:if test="hasFieldErrors() || hasActionMessages() || hasActionErrors()">
<jsp:include page="/jsps/errorHandling.jsp"/>
</s:if>
errorHandling.jsp
This page will display custom message to the users. I am using Struts2-jquery library's dialog box and theme for custom message.
<%@taglib prefix="s" uri="/struts-tags" %>
<%@taglib uri="/struts-jquery-tags" prefix="sj" %>
<div style="visibility:hidden">
<sj:dialog
id="ErrorDialog"
title=" "
modal="true"
width="500"
resizable="false"
buttons="{
'O K':function() {
$(this).dialog('close');
}
}"
>
<h6>
<s:actionmessage theme="jquery"/>
<s:fielderror theme="jquery"/>
<s:actionerror theme="jquery"/>
</h6>
</sj:dialog>
</div>
we add these messages and errors in Action class by overriding following methods:
For ActionMessage- addActionMessage("Logged Out Successfully");
For ActionError- addActionError("You are Not a Valid User");
For FieldError- addFieldError("password", "Please Enter password."); Here first parameter is field name to check for and second parameter is your message to display to users.
The above example to work properly the sj:head tag is required to be included...
ReplyDeleteCheck out these best things to do in Tampa in November, and have an unforgettable journey in the gorgeous city. Book tickets now!
ReplyDeleteIf you are planning to buy a video surveillance system for your business, then we have shared some of the most important aspects that you should consider. At Revlight Security System we serve best commercial cctv camera system for your business.
ReplyDelete