You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Daniel Lipofsky <da...@bricsnet.com> on 2003/11/13 19:12:11 UTC

tag body output

(this is really a taglib question, not struts,
so my apology for being off-topic)

I am designing a security tag which shows or
nukes its body depending on the user.

I got it to work, although I have a question
as to why the simplier code didn't work.
I am just learning and I want to understand.

Here is the working code

public class SecurityTag extends BodyTagSupport {

    protected String saveBody = null;

    public int doStartTag() throws JspException {
        String ts = (String) pageContext.
            getAttribute("TEST-SECURITY",PageContext.SESSION_SCOPE);
        if ("hide".equals(ts)) {
            return SKIP_BODY;
        }
        return EVAL_BODY_BUFFERED;
    }

    public int doAfterBody() throws JspException {

        if (bodyContent != null) {
            saveBody = bodyContent.getString();
        } else {
            saveBody = null;
        }
        return SKIP_BODY;

    }

    public int doEndTag() throws JspException {
        if (saveBody != null)
            ResponseUtils.write(pageContext, saveBody);
        return EVAL_PAGE;
    }

}

My first attempt was to just call
ResponseUtils.write(pageContext, bodyContent.getString())
from doAfterBody().  WHY DIDN'T THAT WORK?
It just output nothing despite the fact that
bodyContent had the content at that point.
Thanks,
Dan

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org