尝试创建演示者时辅助注入错误

时间:2016-04-20 14:56:58

标签: java gwt gwtp gwt-platform gin

我已经使用了Gin辅助注射几次,但我是gwtp的新手,我在尝试使用我的工厂实例化PresenterWidget时遇到了一条我不明白的错误信息,即使在阅读了有关该主题的几篇帖子之后...

[ERROR] Error injecting @com.google.inject.assistedinject.Assisted(value=) java.lang.Integer: 
Unable to create or inherit binding: 
Binding requested for constant key '@com.google.inject.assistedinject.Assisted(value=) java.lang.Integer' but no explicit binding was found; 
Path to required node:
org.moshika.dtp.client.application.book.page.PagePresenter [com.gwtplatform.mvp.client.gin.AbstractPresenterModule.bindPresenterWidget(AbstractPresenterModule.java:260)]

上下文:我必须在屏幕上显示图书的内容。目前我使用具有代理和位置的BookPresenter,我将尝试以PresenterWidget的形式快速绑定/取消绑定页面。我不认为我的页面可以实现为CellWidget,因为我将实现许​​多DTP / WYSIWYG功能。

我的模块:

public class CommonModule extends AbstractGinModule {

@Override
protected void configure() {
    // DefaultPlaceManager Places
    install(new DefaultModule.Builder().defaultPlace(NameTokens.SEARCH).errorPlace(NameTokens.ERROR).unauthorizedPlace(NameTokens.ERROR).build());

    install(new GinFactoryModuleBuilder().build(PagePresenter.Factory.class));

    RestDispatchAsyncModule.Builder dispatchBuilder = new RestDispatchAsyncModule.Builder();
    install(dispatchBuilder.build());

    bindConstant().annotatedWith(RestApplicationPath.class).to("rest");

    bind(ResourceLoader.class).asEagerSingleton();

    bindPresenter(BookPresenter.class, BookPresenter.MyView.class, BookViewTablet.class, BookPresenter.MyProxy.class);

    bindPresenterWidget(PagePresenter.class, PagePresenter.MyView.class, PageViewTablet.class);

}

BookPresenter:

public class BookPresenter extends Presenter<BookPresenter.MyView, BookPresenter.MyProxy>
    implements BookUiHandlers {

    public interface MyView extends View, HasUiHandlers<BookUiHandlers> {
    }

    @ProxyStandard
    @NameToken(NameTokens.BOOK)
    public interface MyProxy extends ProxyPlace<BookPresenter> {
    }

    static final Slot<PagePresenter> SLOT_BOOK = new Slot<PagePresenter>();

    private ResourceDelegate<PageResources> pageDelegate;

    private PagePresenter.Factory factory;

    @Inject
    BookPresenter(EventBus eventBus,
        MyView view, MyProxy proxy,
        ResourceDelegate<PageResources> pageDelegate,
        PagePresenter.Factory factory) {
        super(eventBus, view, proxy, ApplicationPresenter.SLOT_MAIN);

        view.setUiHandlers(this);
        this.pageDelegate= pageDelegate;
        this.factory= factory;
    }

    @Override
    protected void onReveal() {
        super.onReveal();
        NavigationVisibilityEvent.fire(this, true);
        fetchPages(0, 5);
    }

    @Override
    public void fetchPages(final int offset, int limit) {
        pageDelegate.withCallback(new AsyncCallback<List<PageDto>>() {

            @Override
            public void onFailure(Throwable caught) {
                // TODO Auto-generated method stub
            }

            @Override
            public void onSuccess(List<PageDto> dtos) {
                clearSlot(SLOT_BOOK);
                for (PageDto dto : dtos) {
                    PagePresenter pagePresenter = factory.create(dto.getFolioPage());
                    addToSlot(SLOT_DEROULE, pagePresenter);
                    pagePresenter.refreshModel();
                }
            }
        }).list(offset, limit);
    }
}

PagePresenter and Factory:

public class PagePresenter extends PresenterWidget<PagePresenter .MyView>
    implements PageUiHandlers {

    public interface MyView extends View {
        void setFolio(Integer folio);
    }

    public interface Factory {
        CahierPageJourPresenter create(Integer folio);
    }

    private ResourceDelegate<PageResources> pageDelegate;

    private Integer folioPage;

    @Inject
    PagePresenter(EventBus eventBus, MyView view,
        ResourceDelegate<PageResources> pageDelegate,
        @Assisted Integer folio) {
        super(eventBus, view);
        this.pageDelegate= pageDelegate;
        this.folio= folio;
}

    public void refreshModel() {
        pageDelegate.withCallback(new AsyncCallback<PageDto>() {

            @Override
            public void onFailure(Throwable caught) {
                // TODO Auto-generated method stub
            }

            @Override
            public void onSuccess(PageDtodto) {
                getView().setFolio(dto.getFolio());
            }
        }).get(folio);
    }
}

这可能是一个非常愚蠢的错误,因为我没有看到我在同一主题的所有其他帖子中做的不同......

1 个答案:

答案 0 :(得分:1)

如果您想在此处使用辅助注射,请勿直接致电bindPresenterWidget(PagePresenter.class, PagePresenter.MyView.class, PageViewTablet.class);。而是仅绑定视图:bind(PagePresenter.MyView.class).to(PageViewTablet.class);

bindPresenterWidget实际上会调用bind(PagePresenter.class)。然后解析绑定,因为你没有使用@Assisted注释的整数的常量,它会抛出。

如果您一次只能看到一个页面,您还可以使用URL参数来存储页码。然后,您可以覆盖onReset()并根据请求的页面更新内容。这种技术可以避免实例化多个PagePresenter,你可以摆脱辅助工厂。