Wicket

From Resin 3.0

Revision as of 05:04, 7 February 2008 by Ferg (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Contents

Step by Step

[Verified with Resin 3.1.5 and Wicket 1.3.0]

  1. Download Resin from http://caucho.com/download
  2. Untar Resin into /usr/local/share/resin
  3. Download Wicket from http://wicket.apache.org
  4. Unzip Wicket and copy the jars into resin/ext-webapp-lib
  5. Download Velocity from http://velocity.apache.org
  6. Unzip Velocity and copy the jars into resin/ext-webapp-lib
  7. Create a webapp in resin/webapps/wicket
  8. Start Resin with java -jar resin/lib/resin.jar
  9. Create the Hello, World application in resin/webapps/wicket, following http://wicket.apache.org/examples.html
  10. Browse http://localhost:8080/wicket (Resin will autocompile the classes for you)

Enabling MyApplication with Resin's WebBeans

Wicket's MyApplication application can be activated with Resin's WebBeans injection by changing the resin-web.xml configuration slightly. If you set the applicationFactoryClassName init-param to "com.caucho.wicket.ResinApplicationFactory" (and make sure resin-support.jar is in ext-webapp-lib), your MyApplication can use Resin-IoC or WebBeans injection or interception, avoiding any need to use JNDI at all.

<web-app xmlns="http://caucho.com/ns/resin">

    <filter filter-name="wicket"
               filter-class="org.apache.wicket.protocol.http.WicketFilter">
      <init-param 
            applicationClassName="demo.HelloWorldApplication"
            applicationFactoryClassName="com.caucho.wicket.ResinApplicationFactory"/>
    </filter>

    <filter-mapping url-pattern="/*" filter-name="wicket"/>

</web-app>

Your application can then inject any Resin service including DataSources, JMS queues, user-defined beans in the resin-web.xml, etc.

package demo;

import javax.webbeans.*;
import javax.sql.*;

public class MyApplication extends WebApplication {
  @In DataSource _database;

  public Class getHomePage()
  {
    return HelloWorld.class;
  }
}

ResinComponentInjector

Wicket also allows its components to be injected with Resin-managed beans using the @In, @Named, etc. annotations. In particular, DataSources, JPA EntityManagerFactories, JMS Queues, EJB stateless and stateful beans, and application singletons and components can be injected into Wicket components. The wicket capability is limited to injection, so interceptors and @Observes parameters will not be invoked.

To add Resin's injection capabilities to your wicket application, add a ResinComponentInjector to your application:

import com.caucho.wicket.*;

public MyApplication extends WebApplication {
  public MyApplication()
  {
    addComponentInstantiationListener(new ResinComponentInjector());
  }

  ...
}

Wicket will then apply Resin's injection to each component it creates.

ResinWebApplication

As a convenience, the ResinWebApplication class will automatically register Resin's injector for you:

import com.caucho.wicket.*;

public MyApplication extends ResinWebApplication {
  ...
}
Personal tools