如何正确使用ActivityMapper / ActivityManager来定位主页面布局上显示的视图?

时间:2011-04-06 16:23:58

标签: java gwt uibinder gwt-mvp

此应用程序尝试在主显示页面上显示其3个视图,如下所示:

  1. AAAView在“页面顶部”
  2. BBBView在“页面中间”
  3. “页面底部”的CCCView
  4. 问题:虽然应用程序运行,但它不会定位视图(即“AAAView”,“BBBView”,“CCCView”),如上所述。

    (例如,“AAAView”显示在“页面底部”,“BBBView”和“CCCView”显示在“页面中间”...... - 为什么会这样?)

    我认为问题是由于我误用(误解?)ActivityMapper / ActivityManager类在主页上正确放置(或定位)视图/面板。

    不幸的是,我无法找到有关如何正确/有效地使用ActivityMapper / ActivityManager类的任何综合文档。 (到目前为止,我见过的示例应用程序通常过于复杂,无法完全隔离ActivityMapper / ActivityManager类 用于指定面板/视图在主页面上的显示位置)

    应用程序中使用的代码如下所示......

    (对我做错的任何建议或解释都会非常感激...... - 而且,我想我并不是唯一一个在这个概念上苦苦挣扎的人)

    谢谢你的任何帮助!!

    /src/aaa/bbb/ccc/app.gwt.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <module rename-to='app'>
        <inherits name='com.google.gwt.user.User' />
        <inherits name='com.google.gwt.user.theme.standard.Standard' />
        <inherits name="com.google.gwt.activity.Activity" />
        <inherits name="com.google.gwt.place.Place" />
        <entry-point class='aaa.bbb.ccc.client.AppEntryPoint' />
        <source path='client' />
        <source path='shared' />
    </module>
    

    / SRC / AAA / BBB / CCC /客户端/ AppEntryPoint

    package aaa.bbb.ccc.client;
    
    import com.google.gwt.activity.shared.ActivityManager;
    
    public class AppEntryPoint extends LayoutPanel implements EntryPoint
    {
    
        private LayoutPanel mainView = null;
    
        interface AppEntryPointUiBinder extends UiBinder<LayoutPanel, AppEntryPoint>
        {
        }
    
        private static AppEntryPointUiBinder uiBinder = GWT.create(AppEntryPointUiBinder.class);
    
        @UiField
        SimplePanel topOfPage;
    
        @UiField
        SimplePanel middleOfPage;
    
        @UiField
        SimplePanel bottomOfPage;
    
        public AppEntryPoint()
        {
            super();
        }
    
        AcceptsOneWidget top = new AcceptsOneWidget()
        {
            public void setWidget(IsWidget activityWidget)
            {
                Widget widget = Widget.asWidgetOrNull(activityWidget);
                mainView.setWidgetVisible(topOfPage, widget != null);
                topOfPage.setWidget(widget);
            }
        };
    
        AcceptsOneWidget mid = new AcceptsOneWidget()
        {
            public void setWidget(IsWidget activityWidget)
            {
                Widget widget = Widget.asWidgetOrNull(activityWidget);
                mainView.setWidgetVisible(middleOfPage, widget != null);
                middleOfPage.setWidget(widget);
            }
        };    
    
        AcceptsOneWidget bot = new AcceptsOneWidget()
        {
            public void setWidget(IsWidget activityWidget)
            {
                Widget widget = Widget.asWidgetOrNull(activityWidget);
                mainView.setWidgetVisible(bottomOfPage, widget != null);
                bottomOfPage.setWidget(widget);
            }
        };
    
        public void onModuleLoad()
        {
            ClientFactory clientFactory = GWT.create(ClientFactory.class);
            mainView = uiBinder.createAndBindUi(this);
            EventBus eventBus = clientFactory.getEventBus();
    
            ActivityMapper aaaActivityMapper = new AAAActivityMapper(clientFactory);
            ActivityManager aaaActivityManager = new ActivityManager(aaaActivityMapper, eventBus);
            aaaActivityManager.setDisplay(top);
    
            ActivityMapper bbbActivityMapper = new BBBActivityMapper(clientFactory);
            ActivityManager bbbActivityManager = new ActivityManager(bbbActivityMapper, eventBus);
            bbbActivityManager.setDisplay(mid);
    
            ActivityMapper cccActivityMapper = new CCCActivityMapper(clientFactory);
            ActivityManager cccActivityManager = new ActivityManager(cccActivityMapper, eventBus);
            cccActivityManager.setDisplay(bot);
    
            AppPlaceHistoryMapper historyMapper = GWT.create(AppPlaceHistoryMapper.class);
    
            PlaceController placeController = clientFactory.getPlaceController();
            PlaceHistoryHandler historyHandler = new PlaceHistoryHandler(historyMapper);
            historyHandler.register(placeController, eventBus, new AAAPlace());
    
            RootLayoutPanel.get().add(mainView);
            historyHandler.handleCurrentHistory();
        }
    }
    

    /src/aaa/bbb/ccc/client/AppEntryPoint.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:h='urn:import:aaa.bbb.ccc.client'>
        <ui:style src="app.css" />
        <g:LayoutPanel width="800" height='600'>
            <g:layer left='10%' right='10%' top='4px' height='10em'>
                <g:SimplePanel ui:field="topOfPage"/>
            </g:layer>
            <g:layer left='10%' right='10%' top='204px' height='10em'>
                <g:SimplePanel ui:field="middleOfPage"/>
            </g:layer>
            <g:layer left='10%' right='10%' top='404px' height='10em'>
                <g:SimplePanel ui:field="bottomOfPage"/>
            </g:layer>
        </g:LayoutPanel>
    </ui:UiBinder>
    

    /src/aaa/bbb/ccc/client/ClientFactory.java

    package aaa.bbb.ccc.client;
    
    import com.google.gwt.event.shared.EventBus;
    import com.google.gwt.event.shared.SimpleEventBus;
    import com.google.gwt.place.shared.PlaceController;
    
    public class ClientFactory
    {
        public ClientFactory()
        {
        }
    
        private static final EventBus eventBus = new SimpleEventBus();
        private static final PlaceController placeController = new PlaceController(eventBus);
        private static final AAAView aaaView = new AAAView();
        private static final BBBView bbbView = new BBBView();
        private static final CCCView cccView = new CCCView();
    
        public EventBus getEventBus()
        {
            return eventBus;
        }
    
        public PlaceController getPlaceController()
        {
            return placeController;
        }
    
        public AAAView getAAAView()
        {
            return aaaView;
        }
    
        public BBBView getBBBView()
        {
            return bbbView;
        }
    
        public CCCView getCCCView()
        {
            return cccView;
        }
    }
    

    /src/aaa/bbb/ccc/client/AppPlaceHistoryMapper.java

    package aaa.bbb.ccc.client;
    
    import com.google.gwt.place.shared.PlaceHistoryMapper;
    import com.google.gwt.place.shared.WithTokenizers;
    
    @WithTokenizers({AAAPlace.Tokenizer.class, BBBPlace.Tokenizer.class })
    public interface AppPlaceHistoryMapper extends PlaceHistoryMapper
    {
    }
    

    /src/aaa/bbb/ccc/client/AAAView.java

    package aaa.bbb.ccc.client;
    
    import com.google.gwt.core.client.GWT;
    import com.google.gwt.event.dom.client.ClickEvent;
    import com.google.gwt.uibinder.client.UiBinder;
    import com.google.gwt.uibinder.client.UiField;
    import com.google.gwt.uibinder.client.UiHandler;
    import com.google.gwt.user.client.ui.AcceptsOneWidget;
    import com.google.gwt.user.client.ui.Button;
    import com.google.gwt.user.client.ui.HTMLPanel;
    import com.google.gwt.user.client.ui.IsWidget;
    import com.google.gwt.user.client.ui.Label;
    import com.google.gwt.user.client.ui.SimplePanel;
    import com.google.gwt.user.client.ui.Widget;
    
    public class AAAView extends SimplePanel implements IsWidget, AcceptsOneWidget
    {
        private final HTMLPanel aaaView;
        private Presenter presenter;
    
        private static AAAViewUiBinder uiBinder = GWT.create(AAAViewUiBinder.class);   
        interface AAAViewUiBinder extends UiBinder<HTMLPanel, AAAView>
        {
        }
    
        public AAAView()
        {
            aaaView = uiBinder.createAndBindUi(this);
        }
    
        @UiField
        Label aaaViewLabel;
    
        @UiField
        Button bbbButton;
    
        @UiHandler("bbbButton")
        void onBBBButtonClicked(ClickEvent event)
        {
            presenter.gotoBBBPlace();
        }
    
        @UiField
        Button cccButton;
    
        @UiHandler("cccButton")
        void onCCCButtonClicked(ClickEvent event)
        {
            presenter.gotoCCCPlace();
        }
    
        public void setName(String name)
        {
            aaaViewLabel.setText(name);
        }
    
        public void setPresenter(Presenter presenter)
        {
            this.presenter = presenter;
        }    
        public interface Presenter
        {
            void gotoBBBPlace();
            void gotoCCCPlace();
        }
    
        @Override
        public Widget asWidget()
        {
            return aaaView;
        }
    }
    

    /src/aaa/bbb/ccc/client/AAAView.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">
        <ui:style src="app.css" />
        <g:HTMLPanel  ui:field="aaaView" styleName='{style.aaaView}'>
            <g:Label  ui:field="aaaViewLabel" text="AAAView" styleName='{style.viewLabel}'></g:Label>
            <g:Button ui:field="bbbButton" text="go to bbbView"></g:Button>
            <g:Button ui:field="cccButton" text="go to cccView"></g:Button>
        </g:HTMLPanel>
    </ui:UiBinder>
    

    /src/aaa/bbb/ccc/client/AAAActivity.java

    package aaa.bbb.ccc.client;
    
    import com.google.gwt.activity.shared.AbstractActivity;
    import com.google.gwt.event.shared.EventBus;
    import com.google.gwt.place.shared.PlaceController;
    import com.google.gwt.user.client.ui.AcceptsOneWidget;
    
    public class AAAActivity extends AbstractActivity implements AAAView.Presenter
    {
        private String name = "...the AAAView...";    
        private final AAAView aaaView;
        private final PlaceController placeController;
    
        public AAAActivity(ClientFactory clientFactory)
        {
            aaaView = clientFactory.getAAAView();
            placeController = clientFactory.getPlaceController();
        }
    
        @Override
        public void start(AcceptsOneWidget panel, EventBus eventBus)
        {
            aaaView.setPresenter(this);
            aaaView.setName(name);
            panel.setWidget(aaaView.asWidget());
        }    
    
        @Override
        public void gotoBBBPlace()
        {
            placeController.goTo(new BBBPlace());
        }
    
        @Override
        public void gotoCCCPlace()
        {
            placeController.goTo(new CCCPlace());
        }    
    }
    

    /src/aaa/bbb/ccc/client/AAAActivityMapper.java

    package aaa.bbb.ccc.client;
    
    import com.google.gwt.activity.shared.Activity;
    import com.google.gwt.activity.shared.ActivityMapper;
    import com.google.gwt.place.shared.Place;
    
    public class AAAActivityMapper implements ActivityMapper
    {
        private ClientFactory clientFactory;
    
        public AAAActivityMapper(ClientFactory clientFactory)
        {
            this.clientFactory = clientFactory;
        }
    
        @Override
        public Activity getActivity(Place place)
        {
    
            if (place instanceof BBBPlace)
            {
                return new BBBActivity(clientFactory);//return bbbActivityMapper.getActivity(place);
            }
            else
            if (place instanceof CCCPlace)
            {
                return new CCCActivity(clientFactory);//return cccActivityMapper.getActivity(place);
            }
    
            return null;
        }
    }
    

    /src/aaa/bbb/ccc/client/AAAPlace.java

    package aaa.bbb.ccc.client;
    
    import com.google.gwt.place.shared.Place;
    import com.google.gwt.place.shared.PlaceTokenizer;
    import com.google.gwt.place.shared.Prefix;
    
    public class AAAPlace extends Place
    {
        private String aaaName = "AAAPlace";
    
        public AAAPlace()
        {
        }
    
        public String getAAAName()
        {
            return aaaName;
        }
    
        @Prefix("AAAPlace")
        public static class Tokenizer implements PlaceTokenizer<AAAPlace>
        {
            @Override
            public String getToken(AAAPlace place)
            {
                return place.getAAAName(); //"AAAName"; //place.getAAAName();
            }
    
            @Override
            public AAAPlace getPlace(String token)
            {
                return new AAAPlace();
            }
        }
    }
    

    /src/aaa/bbb/ccc/client/BBBView.java

    package aaa.bbb.ccc.client;
    
    import com.google.gwt.core.client.GWT;
    import com.google.gwt.event.dom.client.ClickEvent;
    import com.google.gwt.uibinder.client.UiBinder;
    import com.google.gwt.uibinder.client.UiField;
    import com.google.gwt.uibinder.client.UiHandler;
    import com.google.gwt.user.client.ui.AcceptsOneWidget;
    import com.google.gwt.user.client.ui.Button;
    import com.google.gwt.user.client.ui.HTMLPanel;
    import com.google.gwt.user.client.ui.IsWidget;
    import com.google.gwt.user.client.ui.Label;
    import com.google.gwt.user.client.ui.SimplePanel;
    import com.google.gwt.user.client.ui.Widget;
    
    public class BBBView extends SimplePanel implements IsWidget, AcceptsOneWidget
    {
        private final HTMLPanel bbbView;
        private Presenter presenter;
    
        private static BBBViewUiBinder uiBinder = GWT.create(BBBViewUiBinder.class);    
        interface BBBViewUiBinder extends UiBinder<HTMLPanel, BBBView>
        {
        }
    
        public BBBView()
        {
            bbbView = uiBinder.createAndBindUi(this);
        }
    
        @UiField
        Label bbbViewLabel;
    
        @UiField
        Button aaaButton; 
    
        @UiHandler("aaaButton")
        void onAAAButtonClicked(ClickEvent event)
        {
            presenter.gotoAAAPlace();
        }
    
        @UiField
        Button cccButton; 
    
        @UiHandler("cccButton")
        void onCCCButtonClicked(ClickEvent event)
        {
            presenter.gotoCCCPlace();
        }
    
        public void setName(String name)
        {
            bbbViewLabel.setText(name);
        }
    
        public void setPresenter(Presenter presenter)
        {
            this.presenter = presenter;
        }    
        public interface Presenter
        {
            void gotoAAAPlace();
            void gotoCCCPlace();
        }
    
        @Override
        public Widget asWidget()
        {
            return bbbView;
        }
    }
    

    /src/aaa/bbb/ccc/client/BBBView.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">
        <ui:style src="app.css" />
        <g:HTMLPanel  ui:field="bbbView" styleName='{style.bbbView}'>
            <g:Label  ui:field="bbbViewLabel" text="BBBView" styleName='{style.viewLabel}'></g:Label>
            <g:Button ui:field="aaaButton" text="go to aaaView"></g:Button>
            <g:Button ui:field="cccButton" text="go to cccView"></g:Button>
        </g:HTMLPanel>
    </ui:UiBinder> 
    

    /src/aaa/bbb/ccc/client/BBBActivity.java

    package aaa.bbb.ccc.client;
    
    import com.google.gwt.activity.shared.AbstractActivity;
    import com.google.gwt.event.shared.EventBus;
    import com.google.gwt.place.shared.PlaceController;
    import com.google.gwt.user.client.ui.AcceptsOneWidget;
    
    public class BBBActivity extends AbstractActivity implements BBBView.Presenter
    {
        private String name = "...the BBBView...";    
        private final BBBView bbbView;
        private final PlaceController placeController;
    
        public BBBActivity(ClientFactory clientFactory)
        {
            bbbView = clientFactory.getBBBView();
            placeController = clientFactory.getPlaceController();
        }
    
        @Override
        public void start(AcceptsOneWidget panel, EventBus eventBus)
        {
            bbbView.setPresenter(this);
            bbbView.setName(name);
            panel.setWidget(bbbView.asWidget());
        }    
    
        @Override
        public void gotoAAAPlace()
        {
            placeController.goTo(new AAAPlace());
        }
    
        @Override
        public void gotoCCCPlace()
        {
            placeController.goTo(new CCCPlace());
        }
    }
    

    /src/aaa/bbb/ccc/client/BBBActivityMapper.java

    package aaa.bbb.ccc.client;
    
    import com.google.gwt.activity.shared.Activity;
    import com.google.gwt.activity.shared.ActivityMapper;
    import com.google.gwt.place.shared.Place;
    
    public class BBBActivityMapper implements ActivityMapper
    {
        private ClientFactory clientFactory;
    
        public BBBActivityMapper(ClientFactory clientFactory)
        {
            this.clientFactory = clientFactory;
        }
    
        @Override
        public Activity getActivity(Place place)
        {
            if (place instanceof AAAPlace)
            {
                return new AAAActivity(clientFactory);//aaaActivityMapper.getActivity(place);
            }
            else
            if (place instanceof CCCPlace)
            {
                return new CCCActivity(clientFactory);//return cccActivityMapper.getActivity(place);
            }
    
            return null;
        }
    }
    

    /src/aaa/bbb/ccc/client/BBBPlace.java

    package aaa.bbb.ccc.client;
    
    import com.google.gwt.place.shared.Place;
    import com.google.gwt.place.shared.PlaceTokenizer;
    import com.google.gwt.place.shared.Prefix;
    
    public class BBBPlace extends Place
    {
        private String bbbName = "BBBPlace";
    
        public BBBPlace()
        {
        }
    
        public String getBBBName()
        {
            return bbbName;
        }
    
        @Prefix("BBBPlace")
        public static class Tokenizer implements PlaceTokenizer<BBBPlace>
        {
            @Override
            public String getToken(BBBPlace place)
            {
                return place.getBBBName(); //"BBBName"; //place.getBBBName();
            }
    
            @Override
            public BBBPlace getPlace(String token)
            {
                return new BBBPlace();
            }
        }
    }
    

    /src/aaa/bbb/ccc/client/CCCView.java

    package aaa.bbb.ccc.client;
    
    import com.google.gwt.core.client.GWT;
    import com.google.gwt.event.dom.client.ClickEvent;
    import com.google.gwt.uibinder.client.UiBinder;
    import com.google.gwt.uibinder.client.UiField;
    import com.google.gwt.uibinder.client.UiHandler;
    import com.google.gwt.user.client.ui.AcceptsOneWidget;
    import com.google.gwt.user.client.ui.Button;
    import com.google.gwt.user.client.ui.HTMLPanel;
    import com.google.gwt.user.client.ui.IsWidget;
    import com.google.gwt.user.client.ui.Label;
    import com.google.gwt.user.client.ui.SimplePanel;
    import com.google.gwt.user.client.ui.Widget;
    
    public class CCCView extends SimplePanel implements IsWidget, AcceptsOneWidget
    {
        private final HTMLPanel cccView;
        private Presenter presenter;
    
        private static CCCViewUiBinder uiBinder = GWT.create(CCCViewUiBinder.class);   
        interface CCCViewUiBinder extends UiBinder<HTMLPanel, CCCView>
        {
        }
    
        public CCCView()
        {
            cccView = uiBinder.createAndBindUi(this);
        }
    
        @UiField
        Label cccViewLabel;
    
        @UiField
        Button aaaButton;
    
        @UiHandler("aaaButton")
        void onAAAButtonClicked(ClickEvent event)
        {
            presenter.gotoAAAPlace();
        }
    
        @UiField
        Button bbbButton;
    
        @UiHandler("bbbButton")
        void onBBBButtonClicked(ClickEvent event)
        {
            presenter.gotoBBBPlace();
        }
    
        public void setName(String name)
        {
            cccViewLabel.setText(name);
        }
    
        public void setPresenter(Presenter presenter)
        {
            this.presenter = presenter;
        }    
        public interface Presenter
        {
            void gotoAAAPlace();
            void gotoBBBPlace();
        }
    
        @Override
        public Widget asWidget()
        {
            return cccView;
        }
    }
    

    /src/aaa/bbb/ccc/client/BBBView.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">
        <ui:style src="app.css" />
        <g:HTMLPanel  ui:field="cccView" styleName='{style.cccView}'>
            <g:Label  ui:field="cccViewLabel" text="CCCView" styleName='{style.viewLabel}'></g:Label>
            <g:Button ui:field="aaaButton" text="go to aaaView"></g:Button>
            <g:Button ui:field="bbbButton" text="go to bbbView"></g:Button>
        </g:HTMLPanel>
    </ui:UiBinder>
    

    /src/aaa/bbb/ccc/client/CCCActivity.java

    package aaa.bbb.ccc.client;
    
    import com.google.gwt.activity.shared.AbstractActivity;
    import com.google.gwt.event.shared.EventBus;
    import com.google.gwt.place.shared.PlaceController;
    import com.google.gwt.user.client.ui.AcceptsOneWidget;
    
    public class CCCActivity extends AbstractActivity implements CCCView.Presenter
    {
        private String name = "...the CCCView...";    
        private final CCCView cccView;
        private final PlaceController placeController;
    
        public CCCActivity(ClientFactory clientFactory)
        {
            cccView = clientFactory.getCCCView();
            placeController = clientFactory.getPlaceController();
        }
    
        @Override
        public void start(AcceptsOneWidget panel, EventBus eventBus)
        {
            cccView.setPresenter(this);
            cccView.setName(name);
            panel.setWidget(cccView.asWidget());
        }    
    
        @Override
        public void gotoAAAPlace()
        {
            placeController.goTo(new AAAPlace());
        }
    
        @Override
        public void gotoBBBPlace()
        {
            placeController.goTo(new BBBPlace());
        }    
    }
    

    /src/aaa/bbb/ccc/client/CCCActivityMapper.java

    package aaa.bbb.ccc.client;
    
    import com.google.gwt.activity.shared.Activity;
    import com.google.gwt.activity.shared.ActivityMapper;
    import com.google.gwt.place.shared.Place;
    
    public class CCCActivityMapper implements ActivityMapper
    {
        private ClientFactory clientFactory;
    
        public CCCActivityMapper(ClientFactory clientFactory)
        {
            this.clientFactory = clientFactory;
        }
    
        @Override
        public Activity getActivity(Place place)
        {
            if (place instanceof AAAPlace)
            {
                return new AAAActivity(clientFactory);//return aaaActivityMapper.getActivity(place);
            }
            else
            if (place instanceof BBBPlace)
            {
                return new BBBActivity(clientFactory);//return aaaActivityMapper.getActivity(place);
            }
    
            return null;
        }
    }
    

    /src/aaa/bbb/ccc/client/CCCPlace.java

    package aaa.bbb.ccc.client;
    
    import com.google.gwt.place.shared.Place;
    import com.google.gwt.place.shared.PlaceTokenizer;
    import com.google.gwt.place.shared.Prefix;
    
    public class CCCPlace extends Place
    {
        private String cccName = "CCCPlace";
    
        public CCCPlace()
        {
        }
    
        public String getCCCName()
        {
            return cccName;
        }
    
        @Prefix("CCCPlace")
        public static class Tokenizer implements PlaceTokenizer<CCCPlace>
        {
            @Override
            public String getToken(CCCPlace place)
            {
                return place.getCCCName(); //"CCCName"; //place.getCCCName();
            }
    
            @Override
            public CCCPlace getPlace(String token)
            {
                return new CCCPlace();
            }
        }
    }
    

    /src/aaa/bbb/ccc/client/app.css

    h1 {
        font-size: 2em;
        font-weight: bold;
        color: #777777;
        margin: 40px 0px 70px;
        text-align: center;
    }
    
    .aaaView {
        border-color: black;
        border-width: 2 px;
        background-color: navy;
        width: 75%;
        height: 25%;
    }
    
    .viewLabel {
        color:white;
        font-size: 24px; 
        font-style: italic;
        font-weight: bolder; 
        border-width: 2 px;
    }
    
    .bbbView {
        border-color: black;
        border-width: 2 px;
        background-color: blue;
        width: 75%;
        height: 25%;
    }
    
    .cccView {
        border-color: black;
        border-width: 2 px;
        background-color: lightblue;
        width: 75%;
        height: 25%;
    }
    
    
    .layer1 {
        border-color: red;
        border-width: 2 px;
        background-color: yellow;
        width: 100%;
        height: 33%;
    }
    
    .layer2 {
        border-color: teal;
        border-width: 2 px;
        background-color: green;
        width: 100%;
        height: 33%;
    }
    
    .layer3 {
        border-color: grey;
        border-width: 2 px;
        background-color: aqua;
        width: 100%;
        height: 33%;
    }
    
    .gwt-layer {
        border-color: grey;
        border-width: 2 px;
        background-color: aqua;
        width: 100%;
        height: 33%;    
    }
    

    /war/app.html

    <!doctype html>
    <html>
      <head>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <title>app</title>
        <script type="text/javascript" language="javascript" src="app/app.nocache.js"></script>
      </head>
      <body>
        <iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>
        <noscript>
          <div style="width: 22em; position: absolute; left: 50%; margin-left: -11em; color: red; background-color: white; border: 1px solid red; padding: 4px; font-family: sans-serif">
            Your web browser must have JavaScript enabled
            in order for this application to display correctly.
          </div>
        </noscript>
      </body>
    </html>
    

    /war/WEB-INF/web.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
      <display-name>app</display-name>
      <welcome-file-list>
        <welcome-file>app.html</welcome-file>
      </welcome-file-list>
    </web-app>
    

1 个答案:

答案 0 :(得分:1)

问题出在ActivityMapper s。

当你转到AAAPlace(这是默认位置,所以当你在URL中没有任何历史记录标记时使用的那个):

  • AAAActivityMapper返回null,其中aaaActivityManager将隐藏topOfPage区域
  • BBBActivityMapper会返回AAAActivity,会在AAAView区域中显示(单身)middleOfPage
  • CCCActivityMapper会返回另一个AAAActivity,它会在AAAView区域中显示(单身)bottomOfPage 因为AAAView是一个小部件,所以它一次只能在一个地方显示。因为它是一个单身人士,最后setWidget获胜(它会在将其添加到新父组件之前从其前一个父组件中删除该组件)。由于您在cccActivityManager之后初始化了bbbActivityManager,并且按注册顺序调用了事件处理程序,因此bot获胜。 这会留下一个隐藏的topOfPage,一个空的middleOfPage(未隐藏,因为mid使用非空值调用,但在此之后bot被调用相同的小部件,因此middleOfPage窃取以将其放入bottomOfPage),以及AAAView中的bottomOfPage

无耻的插件:看看http://blog.ltgt.net/gwt-21-activities/(以及关于地点和活动的兄弟文章)。我希望它能帮助你理解它是如何运作的。