问题
Is there any way to use wicket when there is no request associated with current thread. for example i want to periodically send mail and i want to use wicket panels as mail template. but when i use TimerTask
. there is no request in this thread.
is there any way to manually create request in wicket? or any better way to handle such situations?
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.
回答1:
A solution is to use the WicketTester to start panels and get the information you need.
Wickettester tester = new WicketTester(yourApplication);
tester.startComponentInPage(new EmailPanel());
And you can use FormTester to submit a form.
But this is TEST code, so this should not be used in production. I don't know the impact of this on performance, security etc. It's better to extract the email template information you need from the panel and make it usable in a Wicket Panel and and other classes.
来源:https://stackoverflow.com/questions/25086862/use-wicket-without-any-request-associated-with-current-thread