You need to save the ActionErrors object in the request in order to access
it from the JSP. The simplest way to do this is as follows:
In your Action class,
ActionErrors errors = new ActionErrors();
errors.add("<some property name>", new ActionError("some.key"));
// The next step is important if you will use the default attribute name
saveErrors(request, errors);
return mapping.findForward("failure");
In your JSP,
<html:errors/>
This should output all the errors regardless of property name.
----- Original Message -----
From: "Parnell, Giles (AU - Sydney)" <[EMAIL PROTECTED]>
To: "'Struts Users Mailing List'" <[EMAIL PROTECTED]>
Sent: Wednesday, January 15, 2003 6:57 PM
Subject: ActionErrors getting lost between action and JSP
> Hi there guys
>
> Wonder if you can help. I am trying to get the struts actionErrors to
appear
> on my error page.
> I can get them working when I use the html:errors tag and specify the
exact
> error I'm after, however I am now trying to output ALL the errors... with
> zero luck so far.
>
> I have added two errors to the actionErrors object in my action like so:
>
> if (true)
> {
>
> log.error("MAJOR DEBUGGING !!!");
> actionErrors.add("careerPlan.help",
> new ActionError
> ("errors.updatingError", "fingers",
"CareerPlan"));
>
> actionErrors.add("careerPlan.help",
> new ActionError
> ("errors.XMLHydration" ));
>
> //request.setAttribute("errors", errors);
>
> VOErrors errors = new VOErrors(actionErrors);
> request.setAttribute("errors",errors);
> log.debug("Wot is the size of the actionErrors: "
+
> actionErrors.size());
> // XXX this always comes back as 2
>
> // Try just place a string array on request
>
> /*
> String a = "this is my first error";
> String b = "this is my second error";
> String c = "this is my third error";
>
> errors.add(a);
> errors.add(b);
> errors.add(c);
>
> request.setAttribute("errors", errors);
> //XXX this didn't work either XXX
> */
>
> return (mapping.findForward("failure"));
> }
>
> The options i've tryed so far are:
> a)creating actionErrors, adding it to the request, and then forwarding
to
> my error page
> b)creating a VOErrors, adding the actionErrors to the VO and
forwarding
> this VO to my error page
> c)creating an arrayList of strings called errors, and forwarding to
my
> error page
>
> When tracing through my action, on leaving the action I can see that there
> are two errors in the actionErrors object. However on hitting the jsp
page,
> and tracing through the html:errors tag - the errors object is always
empty.
>
> Heres my jsp:
> <%@ page language="java" import="org.apache.struts.action.ActionErrors,
> java.lang.*, java.util.*, au.com.eclipsegroup.egem.valueObject.VOErrors"
%>
>
> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
>
> <%
> response.setHeader("Cache-Control", "no-cache");
> response.setHeader("Pragma", "no-cache");
> response.setDateHeader("Expires", 0);
> %>
>
> <html>
> <head>
> <title>oops in gEm!</title>
> <script language="JavaScript"
> src="../../static/js/rollUp.js"></script>
> <link rel="stylesheet" href="../../static/css/default.css"
> type="text/css">
> </head>
>
> <body bgcolor="#FFFFFF" text="#000000" leftmargin="0"
topmargin="0"
> marginwidth="0" marginheight="0">
>
> <!XXXX DO i even need a form been? ... or can i just place the
> actionErrors in the request and then use the html:errors tag ???>
> <html:form name="errors" scope="request"
> type="au.com.eclipsegroup.egem.valueObject.VOErrors"
> action="/roleTypeCheck.do">
>
> <!-- Top error banner - got the link back to the homepage
> -->
> <jsp:include page="includes/99_errors_nav_top.jsp"/>
>
>
> <table class="table" border="0" cellspacing="0"
> cellpadding="0" align="center">
> <tr>
> <td bgcolor="fed267"
class="normal">
> The following error(s) have occured - please fix or contact the system
> administrator for help. </td>
>
> </tr>
> <tr>
>
> <td bgcolor="fed267"
class="error">
> <!-- XXX debuggin -->
> <% if
> (request.getAttribute("errors") != null)
> {
>
ActionErrors
> e = (ActionErrors) request.getAttribute("errors");
>
>
> if (e !=
> null)
> {
>
int
> size = e.size();
> %>
> <!--XXXX
> this always comes back as 0 XXX -->
> ErrorSize
=
> <%=size%>
> <%
> }
> }
> else
> { %>
> Errors is
> null
> <% } %>
>
>
> <!-- Think this is all i
> need -->
> <html:errors
> name="errors"/></td>
>
>
> <!--html:errors
> name="errors" property="careerPlan.help"/></td -->
>
>
> </tr>
>
> Is there something i'm missing here? Why does the errors attribute
(whether
> it's an array of strings, an actionError object) always seem to lose it's
> value on hitting the jsp page.
>
> Any help would be great. Cheers
> Giles
>
>
> ***********Confidentiality/Limited Liability Statement***************
>
> Have the latest business news and in depth analysis delivered to your
> desktop. Subscribe to "Insights", Deloitte's fortnightly email
> business bulletin . . .
>
> http://www.deloitte.com.au/preferences/preference.asp
>
> This message contains privileged and confidential information intended
> only for the use of the addressee named above. If you are not the
> intended recipient of this message, you must not disseminate, copy or
> take any action in reliance on it. If you have received this message
> in error, please notify Deloitte Touche Tohmatsu immediately. Any
> views expressed in this message are those of the individual sender,
> except where the sender specifically states them to be the views of
> Deloitte.
>
> The liability of Deloitte Touche Tohmatsu, is limited by, and to the
> extent of, the Accountants' Scheme under the Professional Standards
> Act 1994 (NSW).
>
> The sender cannot guarantee that this email or any attachment to it
> is free of computer viruses or other conditions which may damage or
> interfere with data, hardware or software with which it might be used.
> It is sent on the strict condition that the user carries out and relies
> on its own procedures for ensuring that its use will not interfere with
> the recipients systems and the recipient assumes all risk of use and
> absolves the sender of all responsibility for any consequence of its use.
>
>
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.435 / Virus Database: 244 - Release Date: 12/30/2002
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>