mraible
19 Feb 2009, 10:10 AM
I'm using GXT's MVC framework and having success so far. I'm also using DispatcherListeners. My EntryPoint implements HistoryListener and my onHistoryChanged() method looks as follows:
public void onHistoryChanged(String historyToken) {
if (oldHistoryToken != null && historyToken.equals(oldHistoryToken)) return;
// Save the token for the next time round
oldHistoryToken = historyToken;
Dispatcher dispatcher = Dispatcher.get();
if (historyToken != null) {
if (historyToken.equals(HistoryTokens.HOME)) {
dispatcher.dispatch(AppEvents.GoHome);
} else if (historyToken.equals(HistoryTokens.SHOW_LOGIN)) {
dispatcher.dispatch(AppEvents.ShowLogin);
} else if (historyToken.equals(HistoryTokens.SHOW_ADD_CONTACT)) {
dispatcher.dispatch(AppEvents.ShowAddContact);
}
}
}
If I have a Hyperlink like the following.
Hyperlink addContact = new Hyperlink("Add Contact", HistoryTokens.SHOW_ADD_CONTACT);
canvasPanel.add(addContact);
addContact.addClickListener(new ClickListener() {
public void onClick(Widget widget) {
fireEvent(AppEvents.ShowAddContact);
}
});
I've noticed that my controller and DispatcherListener isn't called until onHistoryChanged is called. Is this the recommended way to do things?
If I use dispatcher.dispatch(AppEvents.ShowAddContact), my DispatcherListener is called twice.
Thanks,
Matt
public void onHistoryChanged(String historyToken) {
if (oldHistoryToken != null && historyToken.equals(oldHistoryToken)) return;
// Save the token for the next time round
oldHistoryToken = historyToken;
Dispatcher dispatcher = Dispatcher.get();
if (historyToken != null) {
if (historyToken.equals(HistoryTokens.HOME)) {
dispatcher.dispatch(AppEvents.GoHome);
} else if (historyToken.equals(HistoryTokens.SHOW_LOGIN)) {
dispatcher.dispatch(AppEvents.ShowLogin);
} else if (historyToken.equals(HistoryTokens.SHOW_ADD_CONTACT)) {
dispatcher.dispatch(AppEvents.ShowAddContact);
}
}
}
If I have a Hyperlink like the following.
Hyperlink addContact = new Hyperlink("Add Contact", HistoryTokens.SHOW_ADD_CONTACT);
canvasPanel.add(addContact);
addContact.addClickListener(new ClickListener() {
public void onClick(Widget widget) {
fireEvent(AppEvents.ShowAddContact);
}
});
I've noticed that my controller and DispatcherListener isn't called until onHistoryChanged is called. Is this the recommended way to do things?
If I use dispatcher.dispatch(AppEvents.ShowAddContact), my DispatcherListener is called twice.
Thanks,
Matt