题
我试图用其演示层绑定GWT视图,但似乎没有做任何事情。
这是一个Spring Roo GWT生成的项目,我正在尝试尽可能地使用脚手架。该视图是一个简单的按钮(r.ui.xml),其余视图在r.java中定义:
public class R extends Composite implements RPresenter.Display {
interface MyUiBinder extends UiBinder<Widget, R> {}
private static MyUiBinder uiBinder = GWT.create(MyUiBinder.class);
@UiField Button myButton;
private ClickHandler buttonClickHandler = null;
public R(){
initWidget(uiBinder.createAndBindUi(this));
}
@UiHandler("myButton")
void onButtonClick(ClickEvent event){
GWT.log('Button clicked');
if (buttonClickHandler != null){
GWT.log("buttonClickHandler event triggered");
buttonClickHandler.onClick(event);
}
}
@Override
public void setButtonClickHandler(ClickHandler buttonClickHandler) {
GWT.log("setButtonClickHandler");
this.buttonClickHandler = buttonClickHandler;
}
}
主持人:
public class RPresenter {
public interface Display extends IsWidget {
void setButtonClickHandler(ClickHandler buttonClickHandler);
}
private final Display display;
private final EventBus eventBus;
@Inject
public RPresenter(EventBus eventBus, Display display){
this.display = display;
this.eventBus = eventBus;
bind();
}
private void bind(){
display.setButtonClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
GWT.log("onClick event triggered");
}
});
}
public void go(HasWidgets container){
container.add(display.asWidget());
}
}
对于我的GIN模块,我在...客户端。
public class ScaffoldModule extends AbstractGinModule {
@Override
protected void configure() {
GWT.log("ScaffoldModule configure");
bind(EventBus.class).to(SimpleEventBus.class).in(Singleton.class);
bind(ApplicationRequestFactory.class).toProvider(RequestFactoryProvider.class).in(Singleton.class);
bind(PlaceController.class).toProvider(PlaceControllerProvider.class).in(Singleton.class);
//bind(RPresenter.Display.class).to(R.class).in(Singleton.class);
bind(RPresenter.Display.class).to(R.class);
}
static class PlaceControllerProvider implements Provider<PlaceController> {
private final EventBus eventBus;
@Inject
public PlaceControllerProvider(EventBus eventBus) {
this.eventBus = eventBus;
}
public PlaceController get() {
return new PlaceController(eventBus);
}
}
static class RequestFactoryProvider implements Provider<ApplicationRequestFactory> {
private final EventBus eventBus;
@Inject
public RequestFactoryProvider(EventBus eventBus) {
this.eventBus = eventBus;
}
public ApplicationRequestFactory get() {
ApplicationRequestFactory requestFactory = GWT.create(ApplicationRequestFactory.class);
requestFactory.initialize(eventBus);
return requestFactory;
}
}
}
在GWT开发模式控制台中,“脚手架模块配置”永远不会显示,但是生成的脚手架似乎可以绑定良好代码。
当我将绑定(rpresenter.display.class).to(r.class)放入时,它似乎没有绑定。我在GWT控制台中获得的唯一输出是“单击”,该输出在视图中被调用,然后再也没有进一步。我显然错过了什么,有什么想法吗?
解决方案
GIN使用了摘要的呼叫gwt.log()将不会从AbstractGinModule中输出任何内容 - gin使用了扩展AbstractGinModule的类(在您的情况下的scaffoldModule)。 在编译时 确定要用于注入的接口的具体实现。从您的其余描述中(即UI显示在应用程序中),看来您的依赖注入正常工作。
不隶属于 StackOverflow