Define the helper method to get message resources
public static MessageResources getResources(HttpServletRequest request) {
return ((MessageResources) request.getAttribute(Globals.MESSAGES_KEY));
}
then use resources
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
try {
MessageResources resources = getResources(request);
ActionErrors errors = super.validate(mapping, request);
if (getEmpname() == null || getEmpname().length() < 1) {
errors.add("name", new ActionMessage("error.name.required"));
throw new Exception(getResources(request).getMessage("error.name.required"));
}
return errors;
} catch (Exception ex) {
request.setAttribute(Globals.EXCEPTION_KEY, ex);
return null;
}
}
check the exception key in the request processor
// Check out if exception occurred
Exception exception = (Exception)request.getAttribute(Globals.EXCEPTION_KEY);
if (exception != null){
ActionForward forward = processException(request, response, exception, form, mapping);
processForwardConfig(request, response, forward);
return;
}