Last changed: Okt 03, 2007 19:24 by
Uwe Schaefer Labels:
wicket,
java,
web,
guice,
dependency-injection
You know Wicket
, at least, you´ve heard of it. What you might have missed, is that it integrates with Guice
quite well through this project
.
I´ve tried it and it´s marvellous. Consider this:
public final class SomeForm extends Form
{
public SomeForm(final String componentName)
{
super(componentName);
add(new FeedbackPanel("feedback"));
[... populate form ...]
}
@Inject
private AuditService auditService;
@Override
public final void onSubmit()
{
auditService.doSomeAuditing(...);
doSomethingImportant();
}
[...]
}
The beauty of this is the fact, is that this still works with Serialized forms (of course) and that together with Maven, you have a really good setting for prototyping with Wicket.
Just create your Wicket project, start prototyping your wicket GUI using mvn jetty:run and create/modify Service-interfaces as needed accompanied by Prototype-Implementations (aka NOP-Impls
).
You can later implement your Services for real and just plug them in by switching the Guice-Module:
public abstract class AbstractWebApplication extends WebApplication
{
@Override
protected void init()
{
super.init();
addComponentInstantiationListener(
new GuiceComponentInjector(this,getModule());
}
private Module getModule()
{
return isPrototyping() ?
getPrototypingModule() : getRuntimeModule();
}
protected Module getPrototypingModule()
{
return new Module()
{
public void configure(final Binder binder)
{
binder.bind(AuditService.class).
toInstance(new AuditingServicePrototype());
[...]
}
};
}
}
Lightweight prototyping - Dependencies injected - no XML plus Guice-Scopes are available to give you further flexibility of Object creation.
I love it!