JSP Custom Taglib: Nested Evaluation

Posted by Tiago Fernandez on Stack Overflow See other posts from Stack Overflow or by Tiago Fernandez
Published on 2010-02-24T15:08:12Z Indexed on 2010/03/18 11:51 UTC
Read the original article Hit count: 575

Filed under:
|
|

Say I have my custom taglib:

<%@ taglib uri="http://foo.bar/mytaglib" prefix="mytaglib"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>

<mytaglib:doSomething>
  Test
</mytaglib:doSomething>

Inside the taglib class I need to process a template and tell the JSP to re-evaluate its output, so for example if I have this:

public class MyTaglib extends SimpleTagSupport {

  @Override public void doTag() throws JspException, IOException {
    getJspContext().getOut().println("<c:out value=\"My enclosed tag\"/>");
    getJspBody().invoke(null);
  }
}

The output I have is:

<c:out value="My enclosed tag"/>
Test

When I actually need to output this:

My enclosed tag
Test

Is this feasible? How?

Thanks.

© Stack Overflow or respective owner

Related posts about java

Related posts about jsp