You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@jakarta.apache.org by rw...@us.britannica.com on 2000/02/23 15:59:58 UTC

Custom Tags, dynamic content and jsp:include

I've been working on a simple tag extension that performs a transformation
of an XML document based upon an XSLT stylesheet.  The syntax I'm shooting
for is this:

 <%@ taglib uri="xslt-taglib" prefix="xslt" %>
 <xslt:transform>
  <xslt:doc>
    ...an arbitrary XML document...
  </xslt:doc>
  <xslt:style>
    ...an arbitrary XSLT stylesheet...
  </xslt:style>
 </xslt:transform>

This works fine as long as I've got hard-coded <doc> and <style> bodies.
But what I'd really like to do is this:

  <xslt:transform>
   <xslt:doc>
    <jsp:include page="view.jsp" flush="true" />
   </xslt:doc>
   <xslt:style>
    <jsp:include page="presentation.jsp" flush="true" />
   </xslt:style>
  </xslt:transform>

where view.jsp and presentation.jsp use the implictly passed request and
session parameters to generate the appropriate documents.  This fails, of
course, with a message stating that you can't flush the buffer inside a
custom tag.  This is the correct behavior, according to the 1.1 beta spec: 

"It is not possible to invoke flush on a BodyContent object, as there is no
*backing* stream. This means that it is not legal to do a jsp:include when
out is not bound to the top-level JspWriter." [Section 5.4.5]

But I wonder if there is some workaround (perhaps by clever manipulations of
BodyContent objects?) or another way to accomplish similar behaviour.

More generally, is there some way to grab the output of a <jsp:include> or
<%@ include %> tag rather than having it write directly to the servlet
output stream?  (Or more to the point, to grab the output of a JSP
invocation?) It would be *really* nice (and really powerful) to be able to
pass content dynamically generated by a JSP to beans and custom tags.  (I
know I could always submit an HTTP request and read the output, but then I
lose the implict passing of request attributes.)

Any ideas?
 - Rod