私は非常に単純なVaadinアプリケーションを持っています。Guiceを使用してVaadinアプリのメインウィンドウを挿入したいと思います。
私の問題は、メインウィンドウが挿入されているのに、このメインウィンドウコンポーネント内の@Injectディレクティブが処理されていないことです。
私のusecasの完全なコードソースは、bitbucketリポジトリで入手できます。
Vaadinアプリケーションクラス:
public class MyVaadinApplication extends Application {
protected final Provider<MainWindow> mainWindowProvider;
@Inject
@Named("title")
protected String title;
@Inject
public MyVaadinApplication(Provider<MainWindow> mainWindowProvider) {
this.mainWindowProvider = mainWindowProvider;
}
@Override
public void init() {
System.out.println("MyVaadinApplication:: found value <"+title+"> for injected title");
setMainWindow(this.mainWindowProvider.get());
}
}
MainWindowクラス:
public class MainWindow extends Window {
@Inject
@Named("title")
protected String title;
@Inject
@Named("label")
protected String label;
private static int globalCounter = 0;
private int localCounter;
public MainWindow(String caption, ComponentContainer content) {
super(caption, content);
initUI();
}
public MainWindow(String caption) {
super(caption);
initUI();
}
public MainWindow() {
super();
initUI();
}
private void initUI() {
localCounter = globalCounter;
globalCounter++;
this.setCaption(title);
this.addComponent(new Button(label+" ("+localCounter+")"));
}
}
guiceバインディングが定義されているGuiceServletContextListener :
public class GuicyServletConfig extends GuiceServletContextListener {
@Override
protected Injector getInjector() {
ServletModule module = new ServletModule() {
@Override
protected void configureServlets() {
serve("/*").with(GuiceApplicationServlet.class);
bind(Application.class).to(MyVaadinApplication.class).in(ServletScopes.SESSION);
bind(MainWindow.class).in(ServletScopes.SESSION);
bindConstant().annotatedWith(Names.named("title")).to("This is a guicy Vaadin Application");
bindConstant().annotatedWith(Names.named("label")).to("Guice me!");
}
};
Injector injector = Guice.createInjector(module);
return injector;
}
}
何が起こるかというと、MainWindowは正しく挿入されますが、ラベルとタイトルの文字列は常にnullです。何か案が?