Hi, The included patch adds a couple of methods to the ErrorsTool.java source file, that make it easier to retrieve errors from the global error category. The same can be accomplished with the current methods, by passing them the "org.apache.struts.action.GLOBAL_ERROR" string, but this is against proper development methodology.
Regards, Koen
Index: ErrorsTool.java =================================================================== RCS file: /home/cvspublic/jakarta-velocity-tools/struts/src/java/org/apache/velocity/tools/struts/ErrorsTool.java,v retrieving revision 1.6 diff -u -r1.6 ErrorsTool.java --- ErrorsTool.java 13 Feb 2003 00:22:55 -0000 1.6 +++ ErrorsTool.java 26 Feb 2003 12:15:55 -0000 @@ -83,8 +83,9 @@ * * @author <a href="mailto:[EMAIL PROTECTED]">Gabe Sidler</a> + * @author <a href="mailto:[EMAIL PROTECTED]">Koen Rousseau</a> * - * @version $Id: ErrorsTool.java,v 1.6 2003/02/13 00:22:55 nbubna Exp $ + * @version $Id: ErrorsTool.java,v 1.7 2003/02/26 12:58:55 nbubna Exp $ * */ public class ErrorsTool implements ViewTool @@ -165,8 +166,8 @@ // --------------------------------------------- View Helpers ------------- /** - * <p>Returns <code>true</code> if there are action errors queued, - * otherwise <code>false</code>.</p> + * Returns <code>true</code> if there are action errors queued, + * otherwise <code>false</code>. */ public boolean exist() { @@ -180,8 +181,19 @@ /** - * <p>Returns true if there are action errors queued for the specified - * category of errors, otherwise <code>false</code>.</p> + * Returns <code>true</code> if there are action errors queued for the + * global category (<code>ActionErrors.GLOBAL_ERROR</code>), otherwise + * <code>false</code>. + */ + public boolean existGlobal() + { + return exist(ActionErrors.GLOBAL_ERROR); + } + + + /** + * Returns <code>true</code> if there are action errors queued for the + * specified category of errors, otherwise <code>false</code>. * * @param property the category of errors to check for */ @@ -210,6 +222,15 @@ /** + * Returns the number of action errors queued for the global category. + */ + public int getGlobalSize() + { + return getSize(ActionErrors.GLOBAL_ERROR); + } + + + /** * Returns the number of action errors queued for a particular property. * * @param property the category of errors to check for @@ -229,6 +250,7 @@ * Returns the set of localized error messages as an * <code>java.util.ArrayList</code> of <code> java.lang.String</code> * for all errors queued or <code>null</code> if no errors are queued. + * <p> * If the message resources don't contain an error message for a * particular error key, the key itself is used as error message. */ @@ -241,10 +263,26 @@ /** * Returns the set of localized error messages as an * <code>java.util.ArrayList</code> of <code> java.lang.String</code> + * for all errors queued of the global category or <code>null</code> + * if no error are queued for the specified category. + * <p> + * If the message resources don't contain an error message for a + * particular error key, the key itself is used as error message. + */ + public ArrayList getGlobal() + { + return get(ActionErrors.GLOBAL_ERROR); + } + + + /** + * Returns the set of localized error messages as an + * <code>java.util.ArrayList</code> of <code> java.lang.String</code> * for all errors queued of the specified category or <code>null</code> - * if no error are queued for the specified category. If the message - * resources don't contain an error message for a particular error key, - * the key itself is used as error message. + * if no error are queued for the specified category. + * <p> + * If the message resources don't contain an error message for a + * particular error key, the key itself is used as error message. * * @param property the category of errors to operate on */ @@ -301,11 +339,12 @@ /** - * <p>Renders the queued error messages as a list. This method expects - * the message keys <code>errors.header</code> and <code>errors.footer</code> - * in the message resources. The value of the former is rendered before - * the list of error messages and the value of the latter is rendered - * after the error messages.</p> + * Renders the queued error messages as a list. + * <p> + * This method expects the message keys <code>errors.header</code> + * and <code>errors.footer</code> in the message resources. The value of + * the former is rendered before the list of error messages and the value + * of the latter is rendered after the error messages. * * @return The formatted error messages. If no error messages are queued, * an empty string is returned. @@ -317,12 +356,30 @@ /** - * <p>Renders the queued error messages of a particual category as a list. + * Renders the queued error messages of the global category as a list. + * <p> * This method expects the message keys <code>errors.header</code> and * <code>errors.footer</code> in the message resources. The value of the * former is rendered before the list of error messages and the value of - * the latter is rendered after the error messages.</p> - * + * the latter is rendered after the error messages. + * + * @return The formatted error messages. If no error messages are queued, + * an empty string is returned. + */ + public String getGlobalMsgs() + { + return StrutsUtils.errorMarkup(ActionErrors.GLOBAL_ERROR, request, session, application); + } + + + /** + * Renders the queued error messages of a particual category as a list. + * <p> + * This method expects the message keys <code>errors.header</code> and + * <code>errors.footer</code> in the message resources. The value of the + * former is rendered before the list of error messages and the value of + * the latter is rendered after the error messages. + * * @param property the category of errors to render * * @return The formatted error messages. If no error messages are queued,
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
