我正在尝试在GWTP中使用双重嵌套。 SimpleNestedSample只执行1级。我想(至少)2级。但是,我的最低级别演示者永远不会被揭示(甚至实例化)。在ClientGinjectorBase.java中,我有以下内容:
public interface ClientGinjectorBase extends Ginjector
{
EventBus getEventBus();
PlaceManager getPlaceManager();
Provider<MainPresenter> getMainPresenter();
AsyncProvider<DesktopPresenter> getDesktopPresenter();
AsyncProvider<WebshopAppPresenter> getWebshopAppPresenter();
}
在我的ClientModule.java中,我有以下内容:
public class ClientModule extends AbstractPresenterModule
{
@Override
public void configure()
{
install(new DefaultModule(DesktopPlaceManager.class));
bindConstant().annotatedWith(DefaultPlace.class).to(NameTokens.desktopPage);
bindPresenter(
MainPresenter.class,
MainPresenter.MyView.class,
MainView.class, MainPresenter.MyProxy.class);
bindPresenter(
DesktopPresenter.class,
DesktopPresenter.MyView.class,
DesktopView.class, DesktopPresenter.MyProxy.class);
bindPresenter(
WebshopAppPresenter.class,
WebshopAppPresenter.MyView.class,
WebshopAppView.class, WebshopAppPresenter.MyProxy.class);
}
}
也许有一些明显的错误,但我会很感激一些提示。
谢谢!
答案 0 :(得分:1)
您发布的代码与回答您的问题无关。假设您有4位演示者:
MainPresenter
将包含其他3位演示者。当一个地方被揭露(家庭)时,会触发一个事件。
HomePresenter
代码:
@Override
protected void revealInParent() {
// trigger the setInSlot of MainPageView
RevealContentEvent.fire(this, MainPagePresenter.TYPE_SetMainContent,
this);
}
然后,此事件由setInSlot
的{{1}}处理,它将内容添加到其中一个广告位。这就是为什么MainPageView
应该包含以下代码的3个插槽的原因:
MainPresenter
显示@ContentSlot
public static final Type<RevealContentHandler< ? >> TYPE_SetMainContent = new Type<RevealContentHandler< ? >>();
@ContentSlot
public static final Type<RevealContentHandler< ? >> TYPE_SetHeaderContent = new Type<RevealContentHandler< ? >>();
@ContentSlot
public static final Type<RevealContentHandler< ? >> TYPE_SetNavigationContent = new Type<RevealContentHandler< ? >>();
private boolean headerNavigationDisplayed = false;
@Inject
public MainPagePresenter(final EventBus eventBus, final MyView view,
final MyProxy proxy) {
super(eventBus, view, proxy);
}
@Override
protected void revealInParent() {
// trigger setInSlot in the RootView
RevealRootContentEvent.fire(this, this);
}
@Override
protected void onReveal() {
super.onReveal();
if (!headerNavigationDisplayed) {
// Fire this event to force reveal the header and navigation
// presenters
MainContentSetEvent.fire(this, "ThreePart");
headerNavigationDisplayed = true;
}
}
时。它会触发自定义事件MainPagePresenter
。我有一个参数,但对你来说没有必要。要处理此事件,MainContentSetEvent
必须实现HeaderPresenter
MainContentSetHandler`接口。输入以下代码:
the
对@Override
protected void revealInParent() {
RevealContentEvent.fire(this, MainPagePresenter.TYPE_SetHeaderContent,
this);
}
@ProxyEvent
@Override
public void onMainContentSet(MainContentSetEvent event) {
forceReveal();
}
执行相同操作。输入以下代码:
NavigationPresenter
在视图方面,将以下代码放在@Override
protected void revealInParent() {
RevealContentEvent.fire(this,
MainPagePresenter.TYPE_SetNavigationContent, this);
}
@ProxyEvent
@Override
public void onMainContentSet(MainContentSetEvent event) {
layout = event.getLayout();
forceReveal();
}
:
MainPageView
如果您想了解整个机制,在调试模式下运行,则更容易理解调用的层次结构。我只放了相关的代码,因为你知道@Override
public void setInSlot(Object slot, Widget content) {
if (slot == MainPagePresenter.TYPE_SetMainContent) {
setMainContent(content);
} else if (slot == MainPagePresenter.TYPE_SetHeaderContent) {
setHeaderContent(content);
} else if (slot == MainPagePresenter.TYPE_SetNavigationContent) {
setNavigationContent(content);
} else {
super.setInSlot(slot, content);
}
}
,你应该能够编写丢失的代码。