Wicket Guice updates

I’ve updated the Wicket Guice integration project with some new features. The last of the following wasn’t quite done in time to make the upcoming Wicket 1.3.0-rc1 release, but the other features listed here are in. They are:

  • Support for Provider<T> -based injection.
  • Support for TypeLiteral<T> -based injection.
  • A GuiceWebApplicationFactory, so you can make your WebApplication subclass Guice-managed (see the javadoc for details).

My thanks to JR Boyens for getting the ball rolling on the the first two (WICKET-1063).
Do try it out and give me feedback on configuration issues if it doesn’t quite suit you, preferably so I can fix them for you before the rc2 release.

3 thoughts on “Wicket Guice updates”

  1. Hi there,

    I am trying to do guice injection inside a LoadableDetachableModel and for some reason the filed I inject remains null. Oddly I use the same injection statement for the same object in a Page elsewhere and it works fine. Am I doing something wrong?

    Cheers,

    Callum

  2. Wicket’s Spring and Guice injection don’t work inside models, only inside components. Inject a field of a component, and pass that reference into your model. It’ll do the right thing WRT serialization.

  3. How does Wicket handle references of e.g. a non-serializable service implementation that is passed to a model as Alastair proposed? I assume this will throw a java.io.NotSerializableException. In my opinion Models should be injectable in Wicket like Components. In particular when working with loadable, detachable models you will likely want to inject a service that is responsible for loading the data. If the model a reusable public class, component-only injection will not help.
    Example:

    public class ContactModel extends LoadableDetachableModel {

    private Long contactId;

    @Inject
    private ContactService service;

    public ContactModel(Long contactId) {
    this.contactId = contactId;
    }

    @Override
    protected Contact load() {
    return service.getContact(contactId);
    }

    }

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>