So I'll answer my own question in case anyone else is trying to render html emal with Tap 4.1 The underlying problem was not swapping out the DefaultResponseBuilder from RequestGlobals and also having to implement ResponseBuilder. Here is a snippet of code. ResponseBuilder defaultBuilder = getRequestGlobals(cycle).getResponseBuilder(); IEngine engine = cycle.getEngine(); RequestCycleFactory factory = getRequestCycleFactory(cycle);
IRequestCycle inner = factory.newRequestCycle(engine); String[] subjectAndBody = new String[2]; BaseHTMLMessagePage sendPage = (BaseHTMLMessagePage) getHtmlPage(inner); ByteArrayOutputStream out = new ByteArrayOutputStream(); IMarkupWriter writer = new MarkupWriterImpl("text/html", new PrintWriter(out), new AsciiMarkupFilter()); ResponseBuilder builder = new EmailResponseBuilder(writer, engine.getInfrastructure().getAssetFactory(), false, cycle); getRequestGlobals(cycle).store(builder); inner.activate(sendPage); inner.renderPage(builder); writer.flush(); subjectAndBody[0] = sendPage.getSubject(); subjectAndBody[1] = out.toString(); inner.cleanup(); Notice the storing of the EmailResponseBuilder in requestGlobals and then replacing it with the original DefaultResponseBuilder. I'm not sure if all of this was necessary but it's the only way I could get it to work. I will investigate using hivemind to wire up the EmailResponseBuilder and also the HtmlEmailPage. But for now this is how I got it to work. On 12/7/06, Sam Gendler <[EMAIL PROTECTED]> wrote:
I don't know 4.1, but if you provide a Response and replace the outputstream, you'll likely get what you want. You'll just have to ensure the headers don't get sent, but I believe that is a method you can overload in the Response. --sam On 12/7/06, Dave Kallstrom <[EMAIL PROTECTED]> wrote: > In tapestry versions prior to 4.1 we rendered email message using tapestry > with the following code. > > BaseHTMLMessagePage sendPage = (BaseHTMLMessagePage) getHtmlPage(inner); > ByteArrayOutputStream out = new ByteArrayOutputStream(); > IMarkupWriter writer = new MarkupWriterImpl("text/html", new > PrintWriter(out), new AsciiMarkupFilter()); > inner.activate(sendPage); > inner.renderPage(writer); > writer.flush(); > subjectAndBody[0] = sendPage.getSubject(); > subjectAndBody[1] = out.toString(); > inner.cleanup(); > getRequestGlobals(cycle).store(cycle); > > After recently upgrading to 4.1 this method no longer works. > RequestCycle.renderPage no longer takes an IMarkupWriter but requires a > ResponseBuilder. I've tried the DefaultResponseBuilder which seems to want > to write to the WebResponse instead of the IMarkupWriter that I send it. My > question is how best to make this work again? Do I need to implement a new > ResponseBuilder somehow or extend the DefaultResponseBuilder? Or is there a > better way to render tapestry pages for html email? > -- > Dave Kallstrom > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
-- Dave Kallstrom