Perhaps I did something wrong in my use of the <html:errors> tag with a
specific property, but I believe I've discovered a bug. The problem arises
when I place code like this in a jsp:

        <html:errors property="searchCriteria"/>

I have an ActionError in scope with a name of 'searchCriteria' when this
code is executed. The error message that I specified shows up just fine,
but it is flanked by two nulls. I determined the problem to be the
non-existence of the errors.header and errors.footer properties. If I
defined these two properties, then instead of seeing this:

        null X null

I would see
        
        foo X bar

However, I don't want the header/footer in this instance. What is happening
is that the header and footer are being attached to the legitimate error
message, even when they are null. Here's the code from ErrorsTag.java:

       if ((message != null)&&(property == null) || 
                   propertyMsgPresent) {
           results.append(message);
           results.append("\r\n");
       }

The problem is that if propertyMsgPresent is true, the message var will be
appended even if it is null. (There is a duplicate of this code for the
footer.) I changed it to look like this:

       if ((message != null)&&(property == null) || 
                   (propertyMsgPresent && message != null)) {
           results.append(message);
           results.append("\r\n");
       }

Which checks for the existence of message before appending it. Here's a
unified diff if anyone wants it.

Index: ErrorsTag.java
===================================================================
RCS file:
/home/cvspublic/jakarta-struts/src/share/org/apache/struts/taglib/html/ErrorsTag.java,v
retrieving revision 1.11
diff -u -r1.11 ErrorsTag.java
--- ErrorsTag.java      2001/07/16 00:44:54     1.11
+++ ErrorsTag.java      2001/09/10 19:01:49
@@ -244,7 +244,8 @@
             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) {
+       if ((message != null)&&(property == null) || 
+                  (propertyMsgPresent && message != null)) {
            results.append(message);
            results.append("\r\n");
        }
@@ -264,7 +265,8 @@
             message = RequestUtils.message(pageContext, bundle,
                                            locale, "errors.footer");
 
-    if ((message != null)&&(property == null) || propertyMsgPresent) {
+    if ((message != null)&&(property == null) || 
+           (propertyMsgPresent && message != null)) {
            results.append(message);
            results.append("\r\n");
        }


Joey

-- Sun Certified Java2 Programmer
-- My Pocket Smalltalk Stuff: www.joeygibson.com/st
--
-- "We thought about killin' him, but we kinda 
--  hated to go that far...." - Briscoe Darling

Reply via email to