HowToUseEjbAnnotation

How to use the @EJB annotation in your wicket page

1. Create your EJB, i.e.

@Local
public interface ContactService {
  //.....
}
@Stateless
public class ContactServiceImplementation implements ContactService {
  //....
}

2. Package your ejb in a jar file

3. Declare your ejb in the web.xml descriptor of the web application, i.e.

    <ejb-local-ref>
    	<ejb-ref-name>ejb/contacts</ejb-ref-name>
    	<ejb-ref-type>Session</ejb-ref-type>
    	<local>wicket.javaee.service.ContactService</local>
    </ejb-local-ref>

4. Create your wicket page using the @EJB annotation to reference the developed Ejb, i.e.

public class ListContacts extends WebPage {
	
  @EJB(name="ejb/contacts") private ContactService contactService;
	
  public ListContacts() {
    List<Contact> contacts = contactService.getContacts();
    //....

5. Add the line

addComponentInstantiationListener(new JavaEEComponentInjector(this));

inside the init() method of your Wicket WebApplication?, like in the example:

public class WicketJavaEEApplication extends WebApplication {
	
   protected void init() {
      addComponentInstantiationListener(new JavaEEComponentInjector(this));
   }
}

6. Package your web application in a war file

7. Package the ejb module and the web application in an ear file


Browse Space

- Pages
- News
- Labels
- Attachments
- Bookmarks
- Mail
- Advanced
- Activity

Explore Confluence

- Popular Labels
- Notation Guide

Your Account

Log In

or Sign Up  

Other Features

Add Content