我是Vaadin的新手。我想用它来构建管理员后端。我熟悉DI(Guice),我想将依赖注入servlet。但是,我不知道如何从servlet传递到UI层。以下是我的示例代码:
@Singleton
@VaadinServletConfiguration(productionMode = false, ui = classOf[LoginUI])
class TestServlet @Inject()(userDAO: UserDAO) extends VaadinServlet with LazyLogging {
//How to userDAO to LoginUI?
override def servletInitialized(): Unit = {
}
}
@Theme("valo")
class LoginUI extends UI with LazyLogging {
override def init(request: VaadinRequest) = {
logger.debug("Init Login UI")
val content: VerticalLayout = new VerticalLayout
setContent(content)
val label: Label = new Label("Hello, world!")
content addComponent label
content addComponent new Button("Click Me!",
new ClickListener {
override def buttonClick(event: ClickEvent) =
Notification.show("The time is ")
})
}
}
我看到虽然它是UI,但它就像控制器层一样,所以我认为这样做时不反模式。我发现将内容注入UI更加困难。但是,如果我可以直接注入UI,那就更好了。