开发者

Using EJB in Wicket WebPage

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.j开发者_如何学Pythonava:847)
  ....

There are ejb-module with bean and web-module with servlet and wicket web page deployed to GlassFish v2.1.1 server (if this makes any sense).

What should I do to use my enterprise bean through remote interface in wicket webpage?


The Java EE integration project can be found here: http://wicketstuff.org/confluence/display/STUFFWIKI/wicket-contrib-javaee

As Wicket component instantiation is unmanaged by the DI container, it must provide a proxy injection mechanism. There is a standard way of implementing this, based around the org.apache.wicket.injection.Injector class.


Further to previous answer: due to ejb3 style it is better way to declare name element within @Stateless annotation at 1st step instead of the whole 3rd step in using ejb annotation how to.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜