atlanta.peter
8 Nov 2011, 1:51 PM
public class AppController implements Presenter, ValueChangeHandler<String> {
private final HandlerManager eventBus;
private final SearchServiceAsync searchService;
private HasWidgets container;
private PersonView personView = null;
public AppController(SearchServiceAsync searchService, HandlerManager eventBus) {
this.eventBus = eventBus;
this.searchService = searchService;
bind();
}
private void bind() {
eventBus.addHandler(RetrievePersonEvent.TYPE,
new RetrievePersonEventHandler() {
public void retrievePerson(RetrievePersonEvent event) {
retrievePersonInfo();
}
});
eventBus.addHandler(DisplayPersonEvent.TYPE,
new DisplayPersonEventHandler() {
public void displayPerson(DisplayPersonEvent event,PersonDTO person) {
displayPersonDetails(person);
}
});
}
private void displayPersonDetails(PersonDTO person) {
History.newItem("display", true);
Presenter presenter = new DetailPresenter(UserDetailsServiceAsync.Util.getInstance(), eventBus, new DetailsViewImpl(),person);
presenter.go(container);
}
private void retrievePersonInfo() {
History.newItem("retrieve", true);
Presenter presenter = new PersonPresenter(searchService, eventBus, new SearchResultsViewImpl());
presenter.go(container);
}
public void go(final HasWidgets container) {
this.container = container;
String initToken = History.getToken();
if (initToken.length() == 0)
{
History.newItem("retrieve");
}
History.addValueChangeHandler(this);
History.fireCurrentHistoryState();
}
public void onValueChange(ValueChangeEvent<String> event) {
String token = event.getValue();
if (token != null) {
Presenter presenter = null;
if (token.equals("retrieve")) {
GWT.runAsync(new RunAsyncCallback() {
public void onFailure(Throwable caught) {
}
public void onSuccess() {
// lazily initialize our views, and keep them around to be reused
//
if (personView == null) {
personView = new SearchResultsViewImpl();
}
new PersonPresenter(searchService, eventBus, personView).go(container);
}
} );
} else if (token.equals("display")) {
GWT.runAsync(new RunAsyncCallback() {
public void onFailure(Throwable caught) {
}
public void onSuccess() {
// lazily initialize our views, and keep them around to be reused
//
if (personView == null) {
personView = new DetailsViewImpl();
}
new DetailPresenter(UserDetailsServiceAsync.Util.getInstance(), eventBus,personView ).go(container);
}
} );
}
}
}
}
I call this class from my OnModule method in Entry point. And the issue is When I use OnValueChangeHandler the history.back() ( the browser back button ) is not working.
Any help is appreciated
private final HandlerManager eventBus;
private final SearchServiceAsync searchService;
private HasWidgets container;
private PersonView personView = null;
public AppController(SearchServiceAsync searchService, HandlerManager eventBus) {
this.eventBus = eventBus;
this.searchService = searchService;
bind();
}
private void bind() {
eventBus.addHandler(RetrievePersonEvent.TYPE,
new RetrievePersonEventHandler() {
public void retrievePerson(RetrievePersonEvent event) {
retrievePersonInfo();
}
});
eventBus.addHandler(DisplayPersonEvent.TYPE,
new DisplayPersonEventHandler() {
public void displayPerson(DisplayPersonEvent event,PersonDTO person) {
displayPersonDetails(person);
}
});
}
private void displayPersonDetails(PersonDTO person) {
History.newItem("display", true);
Presenter presenter = new DetailPresenter(UserDetailsServiceAsync.Util.getInstance(), eventBus, new DetailsViewImpl(),person);
presenter.go(container);
}
private void retrievePersonInfo() {
History.newItem("retrieve", true);
Presenter presenter = new PersonPresenter(searchService, eventBus, new SearchResultsViewImpl());
presenter.go(container);
}
public void go(final HasWidgets container) {
this.container = container;
String initToken = History.getToken();
if (initToken.length() == 0)
{
History.newItem("retrieve");
}
History.addValueChangeHandler(this);
History.fireCurrentHistoryState();
}
public void onValueChange(ValueChangeEvent<String> event) {
String token = event.getValue();
if (token != null) {
Presenter presenter = null;
if (token.equals("retrieve")) {
GWT.runAsync(new RunAsyncCallback() {
public void onFailure(Throwable caught) {
}
public void onSuccess() {
// lazily initialize our views, and keep them around to be reused
//
if (personView == null) {
personView = new SearchResultsViewImpl();
}
new PersonPresenter(searchService, eventBus, personView).go(container);
}
} );
} else if (token.equals("display")) {
GWT.runAsync(new RunAsyncCallback() {
public void onFailure(Throwable caught) {
}
public void onSuccess() {
// lazily initialize our views, and keep them around to be reused
//
if (personView == null) {
personView = new DetailsViewImpl();
}
new DetailPresenter(UserDetailsServiceAsync.Util.getInstance(), eventBus,personView ).go(container);
}
} );
}
}
}
}
I call this class from my OnModule method in Entry point. And the issue is When I use OnValueChangeHandler the history.back() ( the browser back button ) is not working.
Any help is appreciated