尝试创建演示者时助攻注射错误
问题描述:
我已经使用过杜松子辅助注射几次,但是我对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和工厂:
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,并且可以摆脱辅助工厂。
非常感谢克里斯托弗。我真的被困住了。现在我明白为什么,但是woooh,我真的找不到解决方案。对于记录来说,我不会在屏幕上显示整本书(或者至少使用像无限滚动这样的延迟加载),并且对于我所理解的,实时对相应的PagePresenter进行实例化似乎是件好事。 –