我已經使用過杜松子輔助注射幾次,但是我對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);
}
}
這可能是一個非常愚蠢的錯誤,因爲我不明白我在做什麼,從同一主題的所有其他職位不同...
非常感謝克里斯託弗。我真的被困住了。現在我明白爲什麼,但是woooh,我真的找不到解決方案。對於記錄來說,我不會在屏幕上顯示整本書(或者至少使用像無限滾動這樣的延遲加載),並且對於我所理解的,實時對相應的PagePresenter進行實例化似乎是件好事。 –