Using EJB in Wicket WebPage
- by Errandir
When I'm using @EJB annotation to access stateless EJB through remote interface in common HttpServlet, it works OK:
public class ListMsgs extends HttpServlet
{
@EJB
private Msgs msgsRI;
...
protected void processRequest(...) ...
{
List msgs = msgsRI.getAll();
...
}
...
}
But when I'm trying the same thing in Wicket WebPage, I'm getting null in return for bean:
public class ListM extends WebPage
{
@EJB
private Msgs msgsRI;
...
public ListM()
{
List msgs = msgsRI.getAll(); // NullPointerException
...
}
...
}
The several lines of this “Unexpected RuntimeException” are:
WicketMessage: Can't instantiate page using constructor public testapp.web.ListM()
Root cause:
java.lang.NullPointerException
at testapp.web.ListM.<init>(ListM.java:22)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.apache.wicket.session.DefaultPageFactory.createPage(DefaultPageFactory.java:192)
at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:57)
at org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.newPage(BookmarkablePageRequestTarget.java:298)
at org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.getPage(BookmarkablePageRequestTarget.java:320)
at org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.processEvents(BookmarkablePageRequestTarget.java:234)
at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1250)
at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329)
at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1428)
at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:479)
at org.apache.wicket.protocol.http.WicketServlet.doGet(WicketServlet.java:138)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
....
There are ejb-module with bean and web-module with servlet and wicket web page deployed to GlassFish v2.1.1 server (if it makes any sense).
What should I do to use my enterprise bean through remote interface in wicket webpage?