You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by hoosssein <ho...@gmail.com> on 2014/08/01 08:35:35 UTC

Create Request Manually

I use Hibernate in wicket and i create a Hibernate Session at the beginning
of each request. now i want to create a TimerTask and work with database but
there is no open session in this thread and if I open session manually, it
doesn't work because my entities work with the session that give form
RequestCycle.get(). so is there any way to manually create a request and
finalize it?

I try this

    final MockWebRequest request = new MockWebRequest(null);
    final NullResponse response = NullResponse.getInstance();
    RequestCycle rc = Application.get().createRequestCycle(request,
response);
    //do jobs
    rc.detach();

but at line 3 it said that There is no application attached to current
thread.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Create-Request-Manually-tp4666838.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: Create Request Manually

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

You should do something like
https://github.com/apache/wicket/blob/master/wicket-core/src/main/java/org/apache/wicket/core/util/string/ComponentRenderer.java#L46
You almost have it.
The only extra thing you should do is to export the Application as a
ThreadLocal. You can get a reference to it by using
Application.get(String). As parameter use the name of the WicketFilter in
your web.xml. The export it with ThreadContext.setApplication(app) and
unexport it in the finally clause.

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov


On Fri, Aug 1, 2014 at 8:35 AM, hoosssein <ho...@gmail.com> wrote:

> I use Hibernate in wicket and i create a Hibernate Session at the beginning
> of each request. now i want to create a TimerTask and work with database
> but
> there is no open session in this thread and if I open session manually, it
> doesn't work because my entities work with the session that give form
> RequestCycle.get(). so is there any way to manually create a request and
> finalize it?
>
> I try this
>
>     final MockWebRequest request = new MockWebRequest(null);
>     final NullResponse response = NullResponse.getInstance();
>     RequestCycle rc = Application.get().createRequestCycle(request,
> response);
>     //do jobs
>     rc.detach();
>
> but at line 3 it said that There is no application attached to current
> thread.
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Create-Request-Manually-tp4666838.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
>
>