|
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 |
|
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 <[hidden email]> 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: [hidden email] For additional commands, e-mail: [hidden email] |
|
Administrator
|
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 <[hidden email]> 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 > <[hidden email]> 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: [hidden email] > For additional commands, e-mail: [hidden email] > > -- 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: [hidden email] For additional commands, e-mail: [hidden email] |
|
saving up vacation days for the caribbean baby :)
-igor On Tue, Nov 4, 2008 at 9:55 AM, Martijn Dashorst <[hidden email]> 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 <[hidden email]> 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 >> <[hidden email]> 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: [hidden email] >> For additional commands, e-mail: [hidden email] >> >> > > > > -- > 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: [hidden email] > For additional commands, e-mail: [hidden email] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|
In reply to this post by Martijn Dashorst
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 <[hidden email]> 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 <[hidden email]> 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 >> <[hidden email]> 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: [hidden email] >> For additional commands, e-mail: [hidden email] >> >> > > > > -- > 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: [hidden email] > For additional commands, e-mail: [hidden email] > > |
|
Great work!
You should put this on the Wiki :-) Am 05.11.2008 um 11:22 schrieb Jörn Zaefferer: > 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 > <[hidden email]> 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 <[hidden email] >> > 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 >>> <[hidden email]> 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: [hidden email] >>> For additional commands, e-mail: [hidden email] >>> >>> >> >> >> >> -- >> 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: [hidden email] >> For additional commands, e-mail: [hidden email] >> >> --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|
In reply to this post by Jörn Zaefferer-2
Is the setAjax(true) absolutely necessary in all cases?
On Wed, Nov 5, 2008 at 5:22 AM, Jörn Zaefferer <[hidden email]> 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 > <[hidden email]> 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 <[hidden email]> 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 >>> <[hidden email]> 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: [hidden email] >>> For additional commands, e-mail: [hidden email] >>> >>> >> >> >> >> -- >> 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: [hidden email] >> For additional commands, e-mail: [hidden email] >> >> > --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|
In reply to this post by Jörn Zaefferer-2
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 <[hidden email]> 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 > <[hidden email]> 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 <[hidden email]> 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 >>> <[hidden email]> 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: [hidden email] >>> For additional commands, e-mail: [hidden email] >>> >>> >> >> >> >> -- >> 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: [hidden email] >> For additional commands, e-mail: [hidden email] >> >> > --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|
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 > <[hidden email]> 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 >> <[hidden email]> 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 <[hidden email] >>> > 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 >>>> <[hidden email]> 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: [hidden email] >>>> For additional commands, e-mail: [hidden email] >>>> >>>> >>> >>> >>> >>> -- >>> 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: [hidden email] >>> For additional commands, e-mail: [hidden email] >>> >>> >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [hidden email] > For additional commands, e-mail: [hidden email] --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|
you still have to do it in a separate thread :)
-igor On Wed, Nov 5, 2008 at 9:14 AM, Peter Ertl <[hidden email]> wrote: > 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 >> <[hidden email]> 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 >>> <[hidden email]> 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 <[hidden email]> >>>> 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 >>>>> <[hidden email]> 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: [hidden email] >>>>> For additional commands, e-mail: [hidden email] >>>>> >>>>> >>>> >>>> >>>> >>>> -- >>>> 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: [hidden email] >>>> For additional commands, e-mail: [hidden email] >>>> >>>> >>> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [hidden email] >> For additional commands, e-mail: [hidden email] > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [hidden email] > For additional commands, e-mail: [hidden email] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|
So would this be ok ?!
(caution! untested!) try { final String html = Executors.newSingleThreadExecutor().submit(new Callable<String>() { public String call() throws Exception { final WicketTester tester = new WicketTester(); tester.startPage(MyPage.class); return new String(tester.getServletResponse().getBinaryContent(), tester.getServletResponse().getCharacterEncoding()); } }).get(); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } Am 05.11.2008 um 18:18 schrieb Igor Vaynberg: > you still have to do it in a separate thread :) > > -igor > > On Wed, Nov 5, 2008 at 9:14 AM, Peter Ertl <[hidden email]> wrote: >> 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 >>> <[hidden email]> 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 >>>> <[hidden email]> 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 <[hidden email] >>>>> > >>>>> 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 >>>>>> <[hidden email]> 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: [hidden email] >>>>>> For additional commands, e-mail: [hidden email] >>>>>> >>>>>> >>>>> >>>>> >>>>> >>>>> -- >>>>> 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: [hidden email] >>>>> For additional commands, e-mail: [hidden email] >>>>> >>>>> >>>> >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: [hidden email] >>> For additional commands, e-mail: [hidden email] >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [hidden email] >> For additional commands, e-mail: [hidden email] >> >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [hidden email] > For additional commands, e-mail: [hidden email] --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|
that should do it for most cases. you might want to give wickettester
the actual application object also. -igor On Wed, Nov 5, 2008 at 9:26 AM, Peter Ertl <[hidden email]> wrote: > So would this be ok ?! > > (caution! untested!) > > > try > { > final String html = Executors.newSingleThreadExecutor().submit(new > Callable<String>() > { > public String call() throws Exception > { > final WicketTester tester = new WicketTester(); > tester.startPage(MyPage.class); > return new String(tester.getServletResponse().getBinaryContent(), > tester.getServletResponse().getCharacterEncoding()); > } > }).get(); > } > catch (InterruptedException e) > { > e.printStackTrace(); > } > catch (ExecutionException e) > { > e.printStackTrace(); > } > > > > > > > Am 05.11.2008 um 18:18 schrieb Igor Vaynberg: > >> you still have to do it in a separate thread :) >> >> -igor >> >> On Wed, Nov 5, 2008 at 9:14 AM, Peter Ertl <[hidden email]> wrote: >>> >>> 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 >>>> <[hidden email]> 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 >>>>> <[hidden email]> 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 >>>>>> <[hidden email]> >>>>>> 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 >>>>>>> <[hidden email]> 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: [hidden email] >>>>>>> For additional commands, e-mail: [hidden email] >>>>>>> >>>>>>> >>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> 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: [hidden email] >>>>>> For additional commands, e-mail: [hidden email] >>>>>> >>>>>> >>>>> >>>> >>>> --------------------------------------------------------------------- >>>> To unsubscribe, e-mail: [hidden email] >>>> For additional commands, e-mail: [hidden email] >>> >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: [hidden email] >>> For additional commands, e-mail: [hidden email] >>> >>> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [hidden email] >> For additional commands, e-mail: [hidden email] > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [hidden email] > For additional commands, e-mail: [hidden email] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|
public String renderPageToString(final WebApplication application, final Page page) { try { return Executors.newSingleThreadExecutor().submit(new Callable<String>() { public String call() throws Exception { final WicketTester tester = new WicketTester(application); tester.startPage(page); tester.assertNoErrorMessage(); return new String(tester.getServletResponse().getBinaryContent(), tester.getServletResponse().getCharacterEncoding()); } }).get(); } catch (InterruptedException e) { throw new WicketRuntimeException(e.getMessage(), e); } catch (ExecutionException e) { throw new WicketRuntimeException(e.getMessage(), e); } } Am 05.11.2008 um 18:31 schrieb Igor Vaynberg: > that should do it for most cases. you might want to give wickettester > the actual application object also. > > -igor > > On Wed, Nov 5, 2008 at 9:26 AM, Peter Ertl <[hidden email]> wrote: >> So would this be ok ?! >> >> (caution! untested!) >> >> >> try >> { >> final String html = >> Executors.newSingleThreadExecutor().submit(new >> Callable<String>() >> { >> public String call() throws Exception >> { >> final WicketTester tester = new WicketTester(); >> tester.startPage(MyPage.class); >> return new >> String(tester.getServletResponse().getBinaryContent(), >> tester.getServletResponse().getCharacterEncoding()); >> } >> }).get(); >> } >> catch (InterruptedException e) >> { >> e.printStackTrace(); >> } >> catch (ExecutionException e) >> { >> e.printStackTrace(); >> } >> >> >> >> >> >> >> Am 05.11.2008 um 18:18 schrieb Igor Vaynberg: >> >>> you still have to do it in a separate thread :) >>> >>> -igor >>> >>> On Wed, Nov 5, 2008 at 9:14 AM, Peter Ertl <[hidden email]> >>> wrote: >>>> >>>> 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 >>>>> <[hidden email]> 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 >>>>>> <[hidden email]> 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 >>>>>>> <[hidden email]> >>>>>>> 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 >>>>>>>> <[hidden email]> 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: [hidden email] >>>>>>>> For additional commands, e-mail: [hidden email] >>>>>>>> >>>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> -- >>>>>>> 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: [hidden email] >>>>>>> For additional commands, e-mail: [hidden email] >>>>>>> >>>>>>> >>>>>> >>>>> >>>>> --------------------------------------------------------------------- >>>>> To unsubscribe, e-mail: [hidden email] >>>>> For additional commands, e-mail: [hidden email] >>>> >>>> >>>> --------------------------------------------------------------------- >>>> To unsubscribe, e-mail: [hidden email] >>>> For additional commands, e-mail: [hidden email] >>>> >>>> >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: [hidden email] >>> For additional commands, e-mail: [hidden email] >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [hidden email] >> For additional commands, e-mail: [hidden email] >> >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [hidden email] > For additional commands, e-mail: [hidden email] --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|
getBinaryContent was not returning anything for me. When i simply changed it to return tester.getServletResponse().getDocument() everything seemed to work.
Here is the sample that works in a jUnit test, I have not yet integrated this into any real applications. public String renderPageToString(final Class<? extends Page> pageClass, final PageParameters pageParameters) { try { final WebApplication app = (WebApplication)WebApplication.get(); return Executors.newSingleThreadExecutor().submit( new Callable<String>() { public String call() throws Exception { final WicketTester tester = new WicketTester(app); tester.startPage(pageClass, pageParameters); tester.assertNoErrorMessage(); return tester.getServletResponse().getDocument(); } }).get(); } catch (InterruptedException e) { throw new WicketRuntimeException(e.getMessage(), e); } catch (ExecutionException e) { throw new WicketRuntimeException(e.getMessage(), e); } }
|
|
cool. let's put this to the wiki (or maybe org.apache.util.* ???) and
help some people out there :-) Am 06.11.2008 um 23:01 schrieb cjlyth: > > getBinaryContent was not returning anything for me. When i simply > changed it > to return tester.getServletResponse().getDocument() everything > seemed to > work. > > Here is the sample that works in a jUnit test, I have not yet > integrated > this into any real applications. > > public String renderPageToString(final Class<? extends Page> > pageClass, > final PageParameters pageParameters) { > try { > final WebApplication app = (WebApplication)WebApplication.get(); > return Executors.newSingleThreadExecutor().submit( > new Callable<String>() { > public String call() throws Exception { > final WicketTester tester = new WicketTester(app); > > tester.startPage(pageClass, pageParameters); > tester.assertNoErrorMessage(); > > return tester.getServletResponse().getDocument(); > } > }).get(); > } catch (InterruptedException e) { > throw new WicketRuntimeException(e.getMessage(), e); > } catch (ExecutionException e) { > throw new WicketRuntimeException(e.getMessage(), e); > } > } > > > > Peter Ertl wrote: >> >> ... >> return new >> String(tester.getServletResponse().getBinaryContent(), >> tester.getServletResponse().getCharacterEncoding()); >> >> ... >> > > -- > View this message in context: http://www.nabble.com/Render-a-Wicket-page-to-a-string-for-HTML-email-tp20325702p20370600.html > Sent from the Wicket - User mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [hidden email] > For additional commands, e-mail: [hidden email] --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|
In reply to this post by cjlyth
> final WebApplication app = (WebApplication)WebApplication.get();
this will not work reliably unless you created a new WicketTester before in your tests or are running inside a current request handled by WicketFilter (needed to initialize the ThreadLocal Application instance in Application) Am 06.11.2008 um 23:01 schrieb cjlyth: > > getBinaryContent was not returning anything for me. When i simply > changed it > to return tester.getServletResponse().getDocument() everything > seemed to > work. > > Here is the sample that works in a jUnit test, I have not yet > integrated > this into any real applications. > > public String renderPageToString(final Class<? extends Page> > pageClass, > final PageParameters pageParameters) { > try { > final WebApplication app = (WebApplication)WebApplication.get(); > return Executors.newSingleThreadExecutor().submit( > new Callable<String>() { > public String call() throws Exception { > final WicketTester tester = new WicketTester(app); > > tester.startPage(pageClass, pageParameters); > tester.assertNoErrorMessage(); > > return tester.getServletResponse().getDocument(); > } > }).get(); > } catch (InterruptedException e) { > throw new WicketRuntimeException(e.getMessage(), e); > } catch (ExecutionException e) { > throw new WicketRuntimeException(e.getMessage(), e); > } > } > > > > Peter Ertl wrote: >> >> ... >> return new >> String(tester.getServletResponse().getBinaryContent(), >> tester.getServletResponse().getCharacterEncoding()); >> >> ... >> > > -- > View this message in context: http://www.nabble.com/Render-a-Wicket-page-to-a-string-for-HTML-email-tp20325702p20370600.html > Sent from the Wicket - User mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [hidden email] > For additional commands, e-mail: [hidden email] --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|
Here is a largely equivalent class that I created. It simply extends
BaseWicketTester. public class PageRenderer extends BaseWicketTester { private final Locale locale; public PageRenderer(Locale locale) { this.locale = locale; } public PageRenderer() { this.locale = null; } private String renderStartPage() { if (this.locale != null) { getWicketSession().setLocale(locale); } return getServletResponse().getDocument(); } public synchronized String render(Class<? extends WebPage> pageClass) { startPage(pageClass); return renderStartPage(); } public synchronized String render(Class<? extends WebPage> pageClass, PageParameters parameters) { startPage(pageClass, parameters); return renderStartPage(); } public synchronized String render(WebPage page) { startPage(page); return renderStartPage(); } } --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|
Yeah this is about the same, I think you would still have to do it in its own thread.
try { return Executors.newSingleThreadExecutor().submit( new Callable<String>() { public String call() throws Exception { return new PageRenderer().render(pageClass, pageParameters); } }).get(); } catch (InterruptedException e) { throw new WicketRuntimeException(e.getMessage(), e); } catch (ExecutionException e) { throw new WicketRuntimeException(e.getMessage(), e); } I think its also worth mentioning that Anatoly Kupriyanov has a template implementation that might solve this problem. However, I like the simpler approach in this thread. http://cwiki.apache.org/confluence/display/WICKET/Use+wicket+as+template+engine
|
|
Ours is running in a separate, non-Wicket process that just generates
and sends e-mail, so there's nothing to step on. But otherwise yes, you would want to protect your ThreadLocal. On Thu, Nov 6, 2008 at 4:52 PM, cjlyth <[hidden email]> wrote: > > Yeah this is about the same, I think you would still have to do it in its own > thread. > > try { > return Executors.newSingleThreadExecutor().submit( > new Callable<String>() { > public String call() throws Exception { > return new PageRenderer().render(pageClass, pageParameters); > } > }).get(); > } catch (InterruptedException e) { > throw new WicketRuntimeException(e.getMessage(), e); > } catch (ExecutionException e) { > throw new WicketRuntimeException(e.getMessage(), e); > } > > I think its also worth mentioning that Anatoly Kupriyanov has a template > implementation that might solve this problem. However, I like the simpler > approach in this thread. > http://cwiki.apache.org/confluence/display/WICKET/Use+wicket+as+template+engine > > > > Scott Swank wrote: >> >> Here is a largely equivalent class that I created. It simply extends >> BaseWicketTester. >> ... >> > > -- > View this message in context: http://www.nabble.com/Render-a-Wicket-page-to-a-string-for-HTML-email-tp20325702p20372800.html > Sent from the Wicket - User mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [hidden email] > For additional commands, e-mail: [hidden email] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|
In reply to this post by scott.swank
That works , thank you!
But I have another question: when I use requestLogger.getLiveSessions() to get the live sessions,the number of sessions always increased after I call the render api. Is it possible to render page of html source in the same session(not create a new one)? Thank you!
|
| Powered by Nabble | Edit this page |
