use wicket without any request associated with current thread

梦想与她 提交于 2019-12-13 06:20:08

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!