HowToUseResourceAnnotation
How to use @Resource annotation in your wicket page
1. Add a resource reference in your web.xml descriptor, i.e.
<env-entry> <env-entry-name>welcomeMessage</env-entry-name> <env-entry-type>java.lang.String</env-entry-type> <env-entry-value>@Welcome</env-entry-value> </env-entry>
2. Use the @Resource annotation in your wicket page, always specifing the name of the referenced resource, i.e.
public class ListContacts extends WebPage {
@Resource(name="welcomeMessage") private String welcome;
public ListContacts() {
new Label(this, "welcomeMessage", welcome);
//.......
3. 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));
}
}