我已经使用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与proxy和place一起使用,我将尝试以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和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);
    }
}


这可能是一个非常愚蠢的错误,因为我看不出自己在做什么,并且与同一主题的所有其他帖子都不一样...

最佳答案

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

bindPresenterWidget实际上调用bind(PagePresenter.class)。然后解析绑定,由于您没有带@Assisted注释的Integer常量,因此它将抛出。

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

08-16 10:09