Wicket
From Resin 3.0
Line 75: | Line 75: | ||
Wicket will then apply Resin's injection to each component it creates. | Wicket will then apply Resin's injection to each component it creates. | ||
− | As a convenience, | + | == ResinWebApplication == |
+ | |||
+ | As a convenience, the <code>ResinWebApplication</code> class will automatically register Resin's injector for you: | ||
<code><pre> | <code><pre> |
Latest revision as of 05:04, 7 February 2008
Contents |
Step by Step
[Verified with Resin 3.1.5 and Wicket 1.3.0]
- Download Resin from http://caucho.com/download
- Untar Resin into /usr/local/share/resin
- Download Wicket from http://wicket.apache.org
- Unzip Wicket and copy the jars into resin/ext-webapp-lib
- Download Velocity from http://velocity.apache.org
- Unzip Velocity and copy the jars into resin/ext-webapp-lib
- Create a webapp in resin/webapps/wicket
- Start Resin with java -jar resin/lib/resin.jar
- Create the Hello, World application in resin/webapps/wicket, following http://wicket.apache.org/examples.html
- 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 {
...
}