rleland     01/06/23 20:22:55

  Modified:    src/share/org/apache/struts/taglib/html ErrorsTag.java
  Log:
  Buzilla 2198 This is a limited patch that doesn't add arguments to the errors
                       tag, which is needed to fully cleanup error reporting.
  Currently given:
  
     <html:errors property="p1"/>
     <html:errors property="p2"/>
     <html:errors property="p3"/>
  
  If there is an error for property "p1",
  an errors.header will be printed for "p2" and "p3" also
  regardless if there is an error
  or not for that property !
  
  The patch below restricts the printing of the header
  to only those properties which have errors, and the global
  <html:errors/> tag.
  
  Revision  Changes    Path
  1.9       +14 -10    
jakarta-struts/src/share/org/apache/struts/taglib/html/ErrorsTag.java
  
  Index: ErrorsTag.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/ErrorsTag.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ErrorsTag.java    2001/04/18 23:32:34     1.8
  +++ ErrorsTag.java    2001/06/24 03:22:55     1.9
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/ErrorsTag.java,v 1.8 
2001/04/18 23:32:34 craigmcc Exp $
  - * $Revision: 1.8 $
  - * $Date: 2001/04/18 23:32:34 $
  + * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/ErrorsTag.java,v 1.9 
2001/06/24 03:22:55 rleland Exp $
  + * $Revision: 1.9 $
  + * $Date: 2001/06/24 03:22:55 $
    *
    * ====================================================================
    *
  @@ -98,7 +98,7 @@
    * </ul>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.8 $ $Date: 2001/04/18 23:32:34 $
  + * @version $Revision: 1.9 $ $Date: 2001/06/24 03:22:55 $
    */
   
   public class ErrorsTag extends TagSupport {
  @@ -230,22 +230,25 @@
               RequestUtils.present(pageContext, bundle, locale, "errors.header");
           boolean footerPresent =
               RequestUtils.present(pageContext, bundle, locale, "errors.footer");
  -        
  +
           // Render the error messages appropriately
        StringBuffer results = new StringBuffer();
           String message = null;
           if (headerPresent)
               message = RequestUtils.message(pageContext, bundle,
                                              locale, "errors.header");
  -     if (message != null) {
  -         results.append(message);
  -         results.append("\r\n");
  -     }
           Iterator reports = null;
           if (property == null)
               reports = errors.get();
           else
               reports = errors.get(property);
  +       // Render header iff this is a global tag or there is an error for this 
property
  +       boolean propertyMsgPresent = reports.hasNext();
  +       if ((message != null)&&(property == null) || propertyMsgPresent) {
  +           results.append(message);
  +           results.append("\r\n");
  +       }
  +
           while (reports.hasNext()) {
               ActionError report = (ActionError) reports.next();
               message = RequestUtils.message(pageContext, bundle,
  @@ -260,7 +263,8 @@
           if (footerPresent)
               message = RequestUtils.message(pageContext, bundle,
                                              locale, "errors.footer");
  -     if (message != null) {
  +
  +        if ((message != null)&&(property == null) || propertyMsgPresent) {
            results.append(message);
            results.append("\r\n");
        }
  
  
  

Reply via email to