struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@locus.apache.org
Subject cvs commit: jakarta-struts/src/share/org/apache/struts/taglib ErrorsTag.java
Date Thu, 12 Oct 2000 21:52:53 GMT
craigmcc    00/10/12 14:52:53

  Modified:    src/share/org/apache/struts/taglib ErrorsTag.java
  Log:
  Modify the <struts:errors> tag to know how to deal with ActionErrors
  objects.
  
  NOTE:  This tag does not yet take advantage of the new abililties of the
  ActionErrors object to associate individual errors with particular fields.
  
  Revision  Changes    Path
  1.9       +34 -22    jakarta-struts/src/share/org/apache/struts/taglib/ErrorsTag.java
  
  Index: ErrorsTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/ErrorsTag.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ErrorsTag.java	2000/08/01 20:03:31	1.8
  +++ ErrorsTag.java	2000/10/12 21:52:52	1.9
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/ErrorsTag.java,v
1.8 2000/08/01 20:03:31 craigmcc Exp $
  - * $Revision: 1.8 $
  - * $Date: 2000/08/01 20:03:31 $
  + * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/ErrorsTag.java,v
1.9 2000/10/12 21:52:52 craigmcc Exp $
  + * $Revision: 1.9 $
  + * $Date: 2000/10/12 21:52:52 $
    *
    * ====================================================================
    *
  @@ -64,12 +64,15 @@
   
   
   import java.io.IOException;
  +import java.util.Iterator;
   import java.util.Locale;
   import javax.servlet.jsp.JspException;
   import javax.servlet.jsp.JspWriter;
   import javax.servlet.jsp.PageContext;
   import javax.servlet.jsp.tagext.TagSupport;
   import org.apache.struts.action.Action;
  +import org.apache.struts.action.ActionError;
  +import org.apache.struts.action.ActionErrors;
   import org.apache.struts.util.BeanUtils;
   import org.apache.struts.util.ErrorMessages;
   import org.apache.struts.util.MessageResources;
  @@ -92,7 +95,7 @@
    * </ul>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.8 $ $Date: 2000/08/01 20:03:31 $
  + * @version $Revision: 1.9 $ $Date: 2000/10/12 21:52:52 $
    */
   
   public final class ErrorsTag extends TagSupport {
  @@ -150,29 +153,34 @@
       public int doStartTag() throws JspException {
   
   	// Were any error messages specified?
  -	String errors[] = null;
  +	ActionErrors errors = new ActionErrors();
   	try {
   	    Object value = pageContext.getAttribute
  -	      (name, PageContext.REQUEST_SCOPE);
  +                (name, PageContext.REQUEST_SCOPE);
   	    if (value == null) {
  -		errors = null;
  +		;
   	    } else if (value instanceof String) {
  -		errors = new String[1];
  -		errors[0] = (String) value;
  +		errors.add(ActionErrors.GLOBAL_ERROR,
  +                           new ActionError((String) value));
   	    } else if (value instanceof String[]) {
  -		errors = (String[]) value;
  -	    } else if (value instanceof ErrorMessages) {
  -		errors = ((ErrorMessages) value).getErrors();
  -		if (errors == null)
  -		    errors = new String[0];
  -	    } else {
  -		errors = new String[1];
  -		errors[0] = value.toString();
  +                String keys[] = (String[]) value;
  +                for (int i = 0; i < keys.length; i++)
  +                    errors.add(ActionErrors.GLOBAL_ERROR,
  +                               new ActionError(keys[i]));
  +            } else if (value instanceof ErrorMessages) {
  +		String keys[] = ((ErrorMessages) value).getErrors();
  +                if (keys == null)
  +                    keys = new String[0];
  +                for (int i = 0; i < keys.length; i++)
  +                    errors.add(ActionErrors.GLOBAL_ERROR,
  +                               new ActionError(keys[i]));
  +            } else if (value instanceof ActionErrors) {
  +                errors = (ActionErrors) value;
   	    }
  -	} catch (Exception e) {
  -	    errors = null;
  +        } catch (Exception e) {
  +            ;
   	}
  -	if (errors == null)
  +        if (errors.empty())
   	    return (EVAL_BODY_INCLUDE);
   
   	// Render the error messages appropriately
  @@ -195,8 +203,12 @@
   	    results.append(message);
   	    results.append("\r\n");
   	}
  -	for (int i = 0; i < errors.length; i++) {
  -	    message = messages.getMessage(locale, errors[i]);
  +        Iterator reports = errors.get();
  +        while (reports.hasNext()) {
  +            ActionError report = (ActionError) reports.next();
  +	    message =
  +                messages.getMessage(locale,
  +                                    report.getKey(), report.getValues());
   	    if (message != null) {
   		results.append(message);
   		results.append("\r\n");
  
  
  

Mime
View raw message