You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Marco <ma...@mkconsultancy.nl> on 2011/06/24 11:42:29 UTC

Render WebPage to String in Wicket 1.5

I need a second opinion about using Wickets template capabilities to send
HTML emails from a Wicket web application.

Situation:
I create an instance of a WebPage which must rendered to a String. This
String is then passed to JavaMail as payload of an email.

The email is created and sent after submitting a Wicket form.
The WebPage is rendered with the following method:

public String renderTemplate(WebPage webPage) {

    BufferedWebResponse bufferedWebResponse = new BufferedWebResponse(null);
    webPage.getRequestCycle().setResponse(bufferedWebResponse);
    webPage.render();
               
    return bufferedWebResponse.getText().toString();
}

It works and in my opinion this is an elegant solution though I'm not too
sure about it.
In Wicket 1.4 I used more code to do the same:
http://www.danwalmsley.com/2008/10/21/render-a-wicket-page-to-a-string-for-html-email/

Am I missing something? 

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Render-WebPage-to-String-in-Wicket-1-5-tp3622130p3622130.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Render WebPage to String in Wicket 1.5

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

I'd recommend to preserve the old reponse, use StrintResponse
temporarily, and at the end in finally{} restore the original
response.

On Fri, Jun 24, 2011 at 12:42 PM, Marco <ma...@mkconsultancy.nl> wrote:
> I need a second opinion about using Wickets template capabilities to send
> HTML emails from a Wicket web application.
>
> Situation:
> I create an instance of a WebPage which must rendered to a String. This
> String is then passed to JavaMail as payload of an email.
>
> The email is created and sent after submitting a Wicket form.
> The WebPage is rendered with the following method:
>
> public String renderTemplate(WebPage webPage) {
>
>    BufferedWebResponse bufferedWebResponse = new BufferedWebResponse(null);
>    webPage.getRequestCycle().setResponse(bufferedWebResponse);
>    webPage.render();
>
>    return bufferedWebResponse.getText().toString();
> }
>
> It works and in my opinion this is an elegant solution though I'm not too
> sure about it.
> In Wicket 1.4 I used more code to do the same:
> http://www.danwalmsley.com/2008/10/21/render-a-wicket-page-to-a-string-for-html-email/
>
> Am I missing something?
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Render-WebPage-to-String-in-Wicket-1-5-tp3622130p3622130.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org