Nested presenters with GWTP

一笑奈何 提交于 2019-12-19 05:22:36

问题


I have content slots in my mainpresenter, how can i put, when app load, put the home presenter in one slot and the menu slot in the another ?

or isn't possible?

thanks in advance.


回答1:


Yes you can ! In the following example code, I assume that your HomePresenter is a place and extends Presenter, and your MenuPresenter extends PresenterWidget.
In your MainPresenter :

@ContentSlot public static final Type<RevealContentHandler<?>> MAIN_SLOT = new Type<RevealContentHandler<?>>();  
@ContentSlot public static final Type<RevealContentHandler<?>> MENU_SLOT = new Type<RevealContentHandler<?>>();

@Override
protected void onReveal() {
    super.onReveal();
    setInSlot(MENU_SLOT, menuPresenter);
}

In your HomePresenter :

@Override
protected void revealInParent() {
    RevealContentEvent.fire(this, MainPresenter.MAIN_SLOT, this);
}

Then in MainView :

@UiField Panel mainContainer;
@UiField Panel menuContainer;

@Override
public void setInSlot(Object slot, Widget content) {
    if (slot == MainPresenter.MAIN_SLOT) {
        mainContainer.clear();
        mainContainer.add(content);
    } else if (slot == MainPresenter.MENU_SLOT) {
        menuContainer.clear();
        menuContainer.add(content);
    } else {
        super.setInSlot(slot, content);
    }
}



回答2:


For users of GWTP 1.5+, note that a lot of new changes have been introduced to slots, and revealing presenters. The case in question may now be accomplished using a NestedSlot for the page content and a PermanentSlot for a menu that you want displayed on all of your pages.

Fortunately, these changes are well documented. See the GWTP slot documentation for an explanation on the new slot types with examples on how to use them.



来源:https://stackoverflow.com/questions/7578123/nested-presenters-with-gwtp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!