0

I am trying to implement history mechanism with a GWT app but has problem with page bookmark i.e. in my case, I have created 3 pages where one get invoked from another. Now, the problem is if page3 is bookmarked then while invoking that bookmark it should open page3 instead now it opens Home page. Why is it so.? What can be the issue.?

I have implemented HistoryConverter as,

@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,

@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);
}
Pratik Rawlekar
  • 327
  • 4
  • 14

1 Answers1

0

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:

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:

[myURL]#getHistoryPageOne

or

[myURL]#getHistoryPageTwo

or

[myURL]#getHistoryPageThree

If you entering:

[myURL]#getHistoryPageThree

to start your application, the tokens will be handle in the convertFromToken-method. You can add the @Debug-annotation to your eventBus to verify that the bookmarked event is fired at the start of your application.

So everything looks good, except the fact, that the Start-event should not have a historyConverter-attribute.

El Hoss
  • 3,767
  • 2
  • 18
  • 24
  • EI Hoss: It worked after removing historyConverter-attribute from start event even if I don't add @Debug-annotation but, in this case if I go to page 3 and I press back button twice it should go to page1 which is not happening. If we add historyConverter-attribute to start event it comes to page1 but bookmark doesn't work in this case. Can you please explain the scenario.? – Pratik Rawlekar Apr 15 '16 at 09:08
  • @Debug annotation shows information about firing and consuming events. not more. – El Hoss Apr 15 '16 at 09:34
  • what do you mean with push the back button twice. You should see the URLs posted above. If you see other URLs than this, you use the history converter also for other events. Do you? – El Hoss Apr 15 '16 at 09:37
  • I mean to say, when I was on page3 the Url was [demoHistoryManager.html#getHistoryPageThree?getHistoryPageThree]. Now, if I press browsers back button the url shown as [demoHistoryManager.html#getHistoryPageTwo?getHistoryPageTwo] i.e. it comes to second page but if I press browsers back button again it should go to first page and url should be [demoHistoryManager.html#getHistoryPageOne?getHistoryPageOne] which is not the case. In my case it remains on second page and url is [demoHistoryManager.html] – Pratik Rawlekar Apr 15 '16 at 10:08
  • History will only go back to pages, you already visited before. – El Hoss Apr 15 '16 at 10:11
  • yes, you are right but I have visited first page and still it doesn't go back to that page. – Pratik Rawlekar Apr 15 '16 at 10:44
  • If you have visited page 1 and the url was created, you should can go back to that page. – El Hoss Apr 15 '16 at 10:56