More J2EE Goodness

I recently needed to capture output for a page to email, as well as
actually output it to the page.  No big deal with CFSAVECONTENT,
of course, but there was one little glitch: occasionally, the core code
needed to use CFFLUSH, and in those cases, the email wasn't needed,
just the screen output.  Rather than screw around with separate
page rendering mechanisms for the two different approaches, a quick
look at the JSP spec yielded this little gem:


This returns the contents of the current buffer.  Note that
it's context sensitive (i.e. if you call it within a tag, it'll return
the contents of the buffer for the tag's body), and there's the
potential for the getString method not to exist, since
it's defined in the BodyContent subclass of JspWriter (what getOut actually returns) that is
used for tag-body buffers.  However, CFMX 6.1 seems to treat the
top-level page as a tag body, so it seems safe to use.

So to
solve my problem, I render my page just as normal, and then if an email
is needed, use that mechanism to pull the contents of the buffer and
send it off. 

Comments are closed.