You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Wim Bervoets <wi...@iconmedialab.com> on 2002/04/03 15:34:09 UTC

Mailer taglib Bug with addRecepient ?

Hello,

Why is the address variable not reset to null in the doAfterBody() function
? (as is done in the doStartTag() in AddReceipientTag )
The problem I had was when I was doing:

<mt:addrecipient type="to"><c:out
value="${param.friendsEmail1}"/></mt:addrecipient>
<mt:addrecipient type="to"><c:out
value="${param.friendsEmail2}"/></mt:addrecipient>

friendsEmail1 is always set, friendsEmail2 can be the empty string.

When <c:out value="${param.friendsEmail2}"/> outputs an empty string then
the mailer taglib sends a mail with 2 times the friendsEmail1 address in the
TO field of the email.

Adding an address = null fixes this problem.


FYI: the current code I'm talking about:

public final int doStartTag() throws JspException {
	// parent tag must be a MailTag, gives access to methods in parent
	myparent =
(MailTag)javax.servlet.jsp.tagext.TagSupport.findAncestorWithClass(this,
MailTag.class);

	if (myparent == null)
	    throw new JspException("addrecipient tag not nested within mail
tag");
	// Make sure type is set..either "to", "cc", or "bcc"
	if ((type != null) && (type.equalsIgnoreCase("to") || 
		type.equalsIgnoreCase("cc") ||
type.equalsIgnoreCase("bcc"))) { 

	    if (address != null) {
		// Try to see if the address attribute was used.
		if (type.equalsIgnoreCase("to"))
		    // set to in the parent tag
		    myparent.addTo(address);
		if (type.equalsIgnoreCase("cc"))
		    // set cc in the parent tag
		    myparent.addCc(address);
		if (type.equalsIgnoreCase("bcc"))
		    // set bcc in the parent tag
		    myparent.addBcc(address);
		address = null;  // reset address
		return SKIP_BODY;
	    } else 
	        return EVAL_BODY_TAG;
	} else
	    throw new JspException("The type attribute is not set. " + 
				 " Specify either \"to\", \"cc\", or
\"bcc\".");
    }


    /**
     *  implementation of the method from the tag interface that tells the
JSP
     *  page what to do after the body of this tag
     *
     *  @throws JSPException  thrown when an error occurs while processing
the
     *                        body of this method
     *
     *  @return SKIP_BODY  int telling the tag handler to not evaluate the
body
     *                     of this tag again
     *
     */
    public final int doAfterBody() throws JspException {
        if ((address = bodyContent.getString()) != null) { 
	    // Try to see if the body was used for the address.
	    if (type.equalsIgnoreCase("to"))
		// set to in the parent tag
		myparent.addTo(address);
	    if (type.equalsIgnoreCase("cc"))
		// set cc in the parent tag
		myparent.addCc(address);
	    if (type.equalsIgnoreCase("bcc"))
		// set bcc in the parent tag
		myparent.addBcc(address);
	    return SKIP_BODY;
	} else 
	    throw new JspException("Address was not found. set " +
			     " the address attribute, or place the address
in" +
			     " the body of the tag.");
    }




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>