简体   繁体   English

为什么页面无法使用GWT / MVP4G中的“历史记录”机制添加书签?

[英]Why page cannot get bookmarked with History mechanism in GWT/MVP4G.?

I am trying to implement history mechanism with a GWT app but has problem with page bookmark ie in my case, I have created 3 pages where one get invoked from another. 我正在尝试使用GWT应用程序实现历史记录机制,但是页面书签存在问题,即在我的情况下,我创建了3个页面,其中一个页面被另一页面调用。 Now, the problem is if page3 is bookmarked then while invoking that bookmark it should open page3 instead now it opens Home page. 现在,问题是,如果page3被加了书签,那么在调用该书签时,它应该打开page3而不是现在打开主页。 Why is it so.? 为什么会这样呢? What can be the issue.? 可能是什么问题?

I have implemented HistoryConverter as, 我已经实现了HistoryConverter为,

@History(type=HistoryConverterType.SIMPLE)
public class MyHistoryConverter implements HistoryConverter<HistoryManagerEventBus> {

public MyHistoryConverter() {

}

@Override
public void convertFromToken(String historyName, String param,HistoryManagerEventBus eventBus) {
    eventBus.dispatch(historyName);     
}

public String convertToToken(String eventType){ 
   return eventType;
}

public String convertToToken(String eventType,HistoryPageTwoView view){    
    return view.getClass().getName();
}

public String convertToToken(String eventType,HistoryPageThreeView view){    
    return view.getClass().getName();
}

@Override
public boolean isCrawlable() {
    return false;
}

}

and eventBus as, 和eventBus as,

@Events(startPresenter = HistoryPageOnePresenter.class,historyOnStart=true)
public interface HistoryManagerEventBus extends EventBusWithLookup {

/**
 * Start event will be fired internally
 */
@Start
@Event(handlers = HistoryPageOnePresenter.class,historyConverter=MyHistoryConverter.class)
void start();

@InitHistory
@Event(handlers = HistoryPageOnePresenter.class)
void init();

@Event(handlers = HistoryPageTwoPresenter.class,historyConverter=MyHistoryConverter.class)
void getHistoryPageTwo();

@Event(handlers=HistoryPageThreePresenter.class,historyConverter=MyHistoryConverter.class)
void getHistoryPageThree();

@Event(handlers=HistoryPageOnePresenter.class,historyConverter=MyHistoryConverter.class)
void getHistoryPageOne();

@Event(handlers=HistoryPageOnePresenter.class)
void setHistoryPageTwo(HistoryPageTwoView view);

@Event(handlers=HistoryPageOnePresenter.class)
void setHistoryPageThree(HistoryPageThreeView view);
}

Assuming that: 假如说:

    @Event(handlers = HistoryPageTwoPresenter.class,historyConverter=MyHistoryConverter.class)
    void getHistoryPageTwo();

    @Event(handlers=HistoryPageThreePresenter.class,historyConverter=MyHistoryConverter.class)
    void getHistoryPageThree();

    @Event(handlers=HistoryPageOnePresenter.class,historyConverter=MyHistoryConverter.class)
    void getHistoryPageOne();

are your navigation events, there is no need to have the following methods inside the MyHistoryConverter class defined: 是您的导航事件,则无需在MyHistoryConverter类中定义以下方法:

public String convertToToken(String eventType,HistoryPageTwoView view){    
    return view.getClass().getName();
}

public String convertToToken(String eventType,HistoryPageThreeView view){    
    return view.getClass().getName();
}

as they are not called to create history tokens. 因为不会调用它们来创建历史记录令牌。

If your history converter works, you should see something like that in your URL: 如果您的历史记录转换器有效,那么您应该在URL中看到类似的内容:

[myURL]#getHistoryPageOne [myURL] #getHistoryPageOne

or 要么

[myURL]#getHistoryPageTwo [myURL]#getHistoryPage2

or 要么

[myURL]#getHistoryPageThree [myURL]#getHistoryPage3

If you entering: 如果输入:

[myURL]#getHistoryPageThree [myURL]#getHistoryPage3

to start your application, the tokens will be handle in the convertFromToken-method. 要启动您的应用程序,令牌将在convertFromToken方法中进行处理。 You can add the @Debug-annotation to your eventBus to verify that the bookmarked event is fired at the start of your application. 您可以将@ Debug-annotation添加到eventBus中,以验证在应用程序启动时是否触发了加书签的事件。

So everything looks good, except the fact, that the Start-event should not have a historyConverter-attribute. 因此,除以下事实外,一切都看起来不错,即启动事件不应具有historyConverter属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM