为什么我无法更新导航栏(PermanentSlot)?

时间:2016-06-19 14:13:22

标签: gwt gwtp gwt-platform

简短摘要:

我尝试在地方更改事件后更新导航栏。为此,我创建了一个GWTP Test*.java,我尝试在SLOT_NavBar中呈现。但是,这不起作用。为了看看我是否做错了什么,我只是在我的SLOT_AdminToolMainContent插槽中进行了渲染,它工作得很好。问题是为什么我可以在一个插槽中渲染TestView而在另一个插槽中不渲染。 GWTP没有给我任何关于我在这里做错的线索,我在文档中找不到任何可以帮助我的东西。

我确定这个问题一定是我身边的误会或者我正在做的事情真的很愚蠢,但我只是没有看到为什么这不起作用的原因。

我在这里有一个“根”主持人:

AdminToolPresenter.java

public class AdminToolPresenter extends Presenter<AdminToolPresenter.MyView, AdminToolPresenter.MyProxy> {

    public interface MyView extends View {      
    }

    @ProxyStandard
    @NameToken(AdminNameTokens.adminTool)
    @UseGatekeeper(AdminGatekeeper.class)
    public interface MyProxy extends ProxyPlace<AdminToolPresenter> {
    }

    /** */
    public static final PermanentSlot<MenuPresenter> SLOT_Menu = new PermanentSlot<>();

    /** */
    public static final NestedSlot SLOT_AdminToolMainContent = new NestedSlot();

    /** */
    private MenuPresenter menuPresenter;

    @Inject
    public AdminToolPresenter(EventBus eventBus, MyView view, MyProxy proxy, MenuPresenter menuPresenter) {
        super(eventBus, view, proxy, RevealType.RootLayout);
        this.menuPresenter = menuPresenter;
    }

    @Override
    protected void onBind() {

        this.setInSlot(SLOT_Menu, this.menuPresenter);
    }

    @Override
    protected void onReveal() {
        LOGGER.fine("AdminToolPresenter.onReveal()");
    }
}

及其观点:

AdminToolView.java

public class AdminToolView extends ViewImpl implements AdminToolPresenter.MyView {

    @SuppressWarnings("unused")
    private final static Logger LOGGER = Logger.getLogger(AdminToolView.class.getName());

    public interface Binder extends UiBinder<Widget, AdminToolView> {
    }

    @UiField HTMLPanel menuPanel;

    @UiField SimplePanel adminMainContent;

    @Inject
    public AdminToolView(Binder uiBinder) {

        this.initWidget(uiBinder.createAndBindUi(this));

        this.bindSlot(AdminToolPresenter.SLOT_Menu, this.menuPanel);
        this.bindSlot(AdminToolPresenter.SLOT_AdminToolMainContent, this.adminMainContent);
    }
}

我正在做的所有工作都很好,例如:

TestPresenter.java

public class TestPresenter extends Presenter<TestPresenter.MyView, TestPresenter.MyProxy> implements TestUiHandlers {

    private final static Logger LOGGER = Logger.getLogger(TestPresenter.class.getName());

    interface MyView extends View , HasUiHandlers<TestUiHandlers> {
    }

    @NameToken(AdminNameTokens.test)
    @ProxyStandard
    interface MyProxy extends ProxyPlace<TestPresenter> {
    }

    @Inject
    TestPresenter(EventBus eventBus, MyView view, MyProxy proxy) {

        // This is working just fine. The content gets displayed correctly in the SLOT_AdminToolMainContent slot
        super(eventBus, view, proxy, AdminToolPresenter.SLOT_AdminToolMainContent);

        this.getView().setUiHandlers(this);
    }

    @Override
    public void prepareFromRequest(PlaceRequest request) {
        LOGGER.severe("prepareFromRequest");
        super.prepareFromRequest(request);
    }

}

TestView.java

class TestView extends ViewWithUiHandlers<TestUiHandlers> implements TestPresenter.MyView {

    interface Binder extends UiBinder<Widget, TestView> {
    }

    @UiField SimplePanel main;

    @Inject TestView(Binder uiBinder) {
        this.initWidget(uiBinder.createAndBindUi(this));
    }
}

完全没问题!但是,如果我尝试将其绑定到另一个插槽:

  

问题

@Inject
TestPresenter(EventBus eventBus, MyView view, MyProxy proxy) {

    // MenuPresenter.SLOT_NavBar instead of AdminToolPresenter.SLOT_AdminToolMainContent
    super(eventBus, view, proxy, MenuPresenter.SLOT_NavBar);

    this.getView().setUiHandlers(this);
}

然后它只是做没有!我只改变了插槽 - 为什么这不起作用?这是MenuPresenter及相关代码:

MenuPresenter.java

public class MenuPresenter extends PresenterWidget<MenuPresenter.MyView> implements MenuUiHandlers {

    private final static Logger LOGGER = Logger.getLogger(MenuPresenter.class.getName());

    interface MyView extends View, HasUiHandlers<MenuUiHandlers> {

    }

    /** Slot for the navigation bar. */
    public static final NestedSlot SLOT_NavBar = new NestedSlot();

    @Inject
    MenuPresenter(EventBus eventBus, MyView view) {     
        super(eventBus, view);      
        this.getView().setUiHandlers(this);
    }

    @Override
    protected void onReveal() {
        LOGGER.severe("onReveal()");
    }
}

MenuView.java

class MenuView extends ViewWithUiHandlers<MenuUiHandlers> implements MenuPresenter.MyView {

    interface Binder extends UiBinder<Widget, MenuView> {
    }

    @UiField HTMLPanel navBarPanel;

    @UiField MaterialSideNav sideNav;

    private PlaceManager placeManager;

    @Inject MenuView(Binder uiBinder, PlaceManager placeManager) {

        this.initWidget(uiBinder.createAndBindUi(this));

        this.bindSlot(MenuPresenter.SLOT_NavBar, this.navBarPanel);

        this.placeManager = placeManager;
    }
}

MenuView.ui.xml

<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
    xmlns:g="urn:import:com.google.gwt.user.client.ui"
    xmlns:m="urn:import:gwt.material.design.client.ui"
    xmlns:m.addins="urn:import:gwt.material.design.addins.client.ui">   
    <ui:with field="tokens" type="com.mz.client.admin.place.AdminNameTokens"/>    
    <ui:style gss="true">
    /* .. */    
    </ui:style> 
    <g:HTMLPanel ui:field="main">

        <g:HTMLPanel addStyleNames="{style.navbar-wrapper}">
            <g:SimplePanel ui:field="navBarPanel" />                        
        </g:HTMLPanel>

        <m:MaterialHeader>

            <m:MaterialNavBar backgroundColor="white" activates="sideNav" layoutPosition="RELATIVE" addStyleNames="{style.nav-bar}">                
                <m:MaterialNavSection>              
                </m:MaterialNavSection>             
            </m:MaterialNavBar >

            <m:MaterialSideNav ui:field="sideNav" m:id="sideNav" type="FIXED" alwaysShowActivator="true" width="280" addStyleNames="{style.side-nav}" >         
                <m:MaterialLink targetHistoryToken="{tokens.getHome}" iconType="HOME" iconPosition="LEFT" textColor="black" text="Home" />                  
            </m:MaterialSideNav>

        </m:MaterialHeader>

    </g:HTMLPanel>
</ui:UiBinder>

请向我解释为什么这不起作用 - 它让我疯了。我没有从GWTP得到任何东西,比如“伙计,你在这里尝试做一些奇怪的事”。没有警告,错误或信息。什么都没有,我不明白我在这里做错了什么!

为了让您了解它的外观:蓝色条是您在 MenuView 中看到的<g:SimplePanel ui:field="navBarPanel"/>

enter image description here

4 个答案:

答案 0 :(得分:0)

您是否尝试将PernamentSlot替换为SingleSlot?我不确定您是否可以更新PernamentSlot

您是否尝试将PresenterWidget替换为Presenter课程中类扩展中的MenuPresenter

MenuView是小部件,没有地方,所以看起来你没有在任何地方添加这个视图,所以它根本不会自己显示它。尝试将一些静态内容放到这个视图中,看看它是否显露出来。

尝试在主视图中添加构造函数widget.add(new MenuView());。其中widget被初始化(使用java或uibinder)视图元素。

要显示常规Presenter(这是一个地方)你必须有一个网址(f.e。:localhost:8080 / myApp | localhost:8080 / myApp#MenuPresenter)。

要显示PresenterWidget您必须在某处调用它!

答案 1 :(得分:0)

根据文件here

  

NestedSlot:与SingleSlot相同,但只能使用 Presenters   代理没有PresenterWidget )。

并且您尝试将cc = bwconncomp(A,4); - 错误放在那里,尝试:

  1. PresenterWidget替换为NestedSlotSlot(接受SingleSlot),
  2. 或更改PresenterWidget以扩展常规MenuPresenter而不是Presenter
  3. 尝试这样做并给我反馈。

答案 2 :(得分:0)

您应该尝试installoperator.attrgetter整个应用程序,然后重启SuperDevMode和您的服务器。

答案 3 :(得分:0)

我重新创建了所描述的功能。有用。我的基础是这篇文章 Layout example 布局示例。希望这会有所帮助。

package pl.korbeldaniel.cms.client.place.app;
public class AppModule extends AbstractPresenterModule {
    @Override
    protected void configure() {
    install(new UiModule());

    bindPresenter(AppPresenter.class, AppPresenter.MyView.class, AppView.class, AppPresenter.MyProxy.class);
    bindPresenter(HomePresenter.class, HomePresenter.MyView.class, HomeView.class, HomePresenter.MyProxy.class);
    bindPresenter(ErrorPresenter.class, ErrorPresenter.MyView.class, 
    bindPresenter(TesttPresenter.class, TesttPresenter.MyView.class, TesttView.class, TesttPresenter.MyProxy.class);

    }
}
package pl.korbeldaniel.cms.client.place.app;

public class AppPresenter extends TabContainerPresenter<AppPresenter.MyView, AppPresenter.MyProxy> implements AppUiHandlers, CurrentUserChangedHandler, AsyncCallStartHandler, AsyncCallFailHandler, AsyncCallSucceedHandler {
    @ProxyStandard
    public interface MyProxy extends Proxy<AppPresenter> {}
    public interface MyView extends TabView, HasUiHandlers<AppUiHandlers> {}

    public static final NestedSlot SLOT_NavBar = new NestedSlot();
    private final TesttPresenter testtPresenter;

    @Inject
    AppPresenter(EventBus eventBus, MyView view, MyProxy proxy, TesttPresenter testtPresenter) {
        super(eventBus, view, proxy, SLOT_TAB_CONTENT, SLOT_REQUEST_TABS, SLOT_CHANGE_TAB, RevealType.Root);
        this.testtPresenter = testtPresenter;
        getView().setUiHandlers(this);
    }
    @Override
    protected void onBind() {
        super.onBind();
        setInSlot(SLOT_NavBar, testtPresenter);
    }
}
package pl.korbeldaniel.cms.client.place.app;

public class AppView extends ViewWithUiHandlers<AppUiHandlers> implements AppPresenter.MyView {
    public interface Binder extends UiBinder<Widget, AppView> {}

    @UiField MaterialRow navBarPanel;

    @Inject
    AppView(Binder uiBinder) {
        initWidget(uiBinder.createAndBindUi(this));
        bindSlot(AppPresenter.SLOT_NavBar, navBarPanel);
    }
}
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
    xmlns:g='urn:import:com.google.gwt.user.client.ui' xmlns:m="urn:import:gwt.material.design.client.ui"

    <m:MaterialPanel>
      <m:MaterialRow ui:field="navBarPanel" />                        
    </m:MaterialPanel>
</ui:UiBinder>
package pl.korbeldaniel.cms.client.playground.test.testt;

import pl.korbeldaniel.cms.client.place.app.AppPresenter;

public class TesttPresenter extends Presenter<TesttPresenter.MyView, TesttPresenter.MyProxy> {
    public interface MyView extends View {}
    @ProxyStandard
    public interface MyProxy extends Proxy<TesttPresenter> {}
    @Inject
    public TesttPresenter(EventBus eventBus, MyView view, MyProxy proxy) {
        super(eventBus, view, proxy, AppPresenter.SLOT_NavBar);
    }
}
package pl.korbeldaniel.cms.client.playground.test.testt;

import pl.korbeldaniel.cms.client.place.app.AppPresenter;

public class TesttView extends ViewImpl implements TesttPresenter.MyView {
    public interface Binder extends UiBinder<Widget, TesttView> {}
    @UiField
    SimplePanel main;
    @Inject
    public TesttView(Binder uiBinder) {
        initWidget(uiBinder.createAndBindUi(this));
        main.add(new Label("____________________________________________________________________________________________________________________>TEST "));
        Window.alert("TESTT");
        this.bindSlot(AppPresenter.SLOT_NavBar, this.main);
    }
}
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
             xmlns:g="urn:import:com.google.gwt.user.client.ui">
    <g:SimplePanel ui:field="main"></g:SimplePanel>
</ui:UiBinder>