From your description of the problem, it doesn’t really seem like you need a 
renderer — perhaps abstracting out the search criterion as a pure java 
(non-wicket-specific) object that can be used both in the UI and in data export 
would be a better approach.

That said, here’s what I’m doing to render pages (batch emails) in a background 
thread:
public static void sendMail(EmailBatch batch) {
    Application app = ThreadContext.getApplication();
    RequestCycle requestCycle = ThreadContext.getRequestCycle();
    Session session = ThreadContext.getSession();

    Runnable r = () -> {
        ThreadContext.setApplication(app);
        ThreadContext.setRequestCycle(requestCycle);
        ThreadContext.setSession(session);
<blah blah blah>
        ComponentRenderer.renderPage(new 
PageProvider(EmailMergeProcessor.class, pp)

There are some restrictions on what the pages can contain (for example, I had 
to disable bootstrap), but eventually I got the above to work.  Your mileage 
may vary.  Good luck.

-Don



> On May 29, 2015, at 1:49 AM, Peter Henderson <peter.hender...@starjar.com> 
> wrote:
> 
> On Fri, May 29, 2015 at 9:22 AM, Christoph Läubrich <lae...@googlemail.com 
> <mailto:lae...@googlemail.com>>
> wrote:
> 
>> Can you explain what is the reason for using a background-thread?
>> Depending on your container you might want to use e.g. Continuations or
>> Servlet-Async to compute lengthy values in the background and then let
>> render the page as normal in the RequestCycle depending on that result.
>> 
>> 
> In my real application the background thread is a data export routine. I
> want to run a list panel with saved page parameters and instead of
> rendering the html I'll access the underlying list model to extract the
> data, export to csv (or json,etc) and pass it out for other processing.
> This way the user can fiddle about with the search filters on the list to
> see exactly what they want and later get the raw data (accountants love
> spreadsheets).
> 
> For example.
> This page [1] I'd like to have a plain servlet which can run the component
> outside of wicket.
> 
> 
> Peter.
> 
> 
> 
> [1]
> https://demo.starjar.com:25000/Starjar/protected/project/1210005?rpp=25&fn1=Description+Contains&fn2=Date+%5Bmonth+year%5D&fv2=2015+1+1&tab=Time+Sheets
>  
> <https://demo.starjar.com:25000/Starjar/protected/project/1210005?rpp=25&fn1=Description+Contains&fn2=Date+%5Bmonth+year%5D&fv2=2015+1+1&tab=Time+Sheets>
> 
> 
> 
>> Am 28.05.2015 11:51, schrieb Peter Henderson:
>> 
>>> Hi
>>> 
>>> I am trying to render a component in a background thread.
>>> 
>>> My first attempt fails with an Exception
>>> "There is no application attached to current thread Thread-4"
>>> 
>>> 
>>> 
>>> So I link the application with the background thread and now a different
>>> exception.
>>> java.lang.IllegalArgumentException: Argument 'requestCycle' may not be
>>> null.
>>>     at org.apache.wicket.util.lang.Args.notNull(Args.java:41)
>>>     at
>>> 
>>> org.apache.wicket.Application.fetchCreateAndSetSession(Application.java:1568)
>>>     at org.apache.wicket.Session.get(Session.java:171)
>>> 
>>> 
>>> Is component renderer designed to work from a background thread?
>>> 
>>> 
>>> I've put a quick start on git hub.
>>> https://github.com/bollinger/wicket-ComponentRenderer
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
>> For additional commands, e-mail: users-h...@wicket.apache.org
>> 
>> 
> 
> 
> -- 
> Peter Henderson
> 
> Director
> Starjar Ltd.
> www.starjar.com <http://www.starjar.com/>
> 0330 088 1662

Reply via email to