Won't it be easier / will it work to use WicketTester for this?


Am 05.11.2008 um 17:26 schrieb Igor Vaynberg:

make sure you do this in a thread other then the request thread so you
dont mess up any threadlocals.

-igor

On Wed, Nov 5, 2008 at 2:22 AM, Jörn Zaefferer
<[EMAIL PROTECTED]> wrote:
No voodoo neccessary, got it working:

protected String renderPage(Class<? extends Page> pageClass,
PageParameters pageParameters) {

              //get the servlet context
WebApplication application = (WebApplication) WebApplication.get();

ServletContext context = application.getServletContext();

              //fake a request/response cycle
MockHttpSession servletSession = new MockHttpSession(context);
              servletSession.setTemporary(true);

MockHttpServletRequest servletRequest = new MockHttpServletRequest(
                              application, servletSession, context);
MockHttpServletResponse servletResponse = new MockHttpServletResponse(
                              servletRequest);

              //initialize request and response
              servletRequest.initialize();
              servletResponse.initialize();

WebRequest webRequest = new ServletWebRequest(servletRequest);

BufferedWebResponse webResponse = new BufferedWebResponse(servletResponse);
              webResponse.setAjax(true);

              WebRequestCycle requestCycle = new WebRequestCycle(
                              application, webRequest, webResponse);

              requestCycle.setRequestTarget(new
BookmarkablePageRequestTarget(pageClass, pageParameters));

              try {
requestCycle.getProcessor().respond(requestCycle);

log.warn("Response after request: "+webResponse.toString());

                      if (requestCycle.wasHandled() == false) {
requestCycle.setRequestTarget(new WebErrorCodeResponseTarget( HttpServletResponse.SC_NOT_FOUND));
                      }
                      requestCycle.detach();

              } finally {
                      requestCycle.getResponse().close();
              }

              return webResponse.toString();
      }

Does it make sense to put this in a ticket to request it for Wicket 1.5?

Jörn

On Tue, Nov 4, 2008 at 5:55 PM, Martijn Dashorst
<[EMAIL PROTECTED]> wrote:
Are you in New Orleans in some voodoo bar? Why not join us at ApacheCon? :)

Martijn

On Tue, Nov 4, 2008 at 10:43 AM, Igor Vaynberg <[EMAIL PROTECTED] > wrote:
without seeing your code we have to resort to waving a dead chicken in
front of our screens or making swags.

-igor

On Tue, Nov 4, 2008 at 9:19 AM, Jörn Zaefferer
<[EMAIL PROTECTED]> wrote:
Hi,

I've found this article on how to render a page to a String:
http://www.danwalmsley.com/2008/10/21/render-a-wicket-page-to-a-string-for-html-email/

It seemed to be exactly what I was looking for. Copying the code into
my app, I got a compiler error on the line where the WebRequest is
created. Using the constructor to ServletWebRequest helped.

Nonetheless, I get only an empty string back, no clue whats going wrong.

I'm using Wicket 1.3.5.

Any ideas?

Jörn


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





--
Become a Wicket expert, learn from the best: http://wicketinaction.com
Apache Wicket 1.3.4 is released
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to