Saving Navigation / History State in GWT with MVP Template

I have implemented the basic MVP- based GWT application that Google recommends. What I'm trying to figure out is the best way to keep the navigation / history state after populating your application with data.

Say you have a search that returns addition data in a CellTable. If I move to a certain element in the search results to another panel, the initial panel with the search result will disappear if Presenter / View is not stored somewhere so that I can easily access it during reverse navigation.

So my question is: what do apps like Gmail do to maintain state for reverse navigation? Are there any examples of how this can be implemented?

+3
source share
3 answers

Gmail does not use GWT, so I assume you just want a high level response.

Gmail uses the URL fragment (part after #). When you navigate to Gmail, you'll notice that the snippet changes to a unique identifier for each "location" in the Gmail navigation. Using this snippet, the browser does all the tracking for you, without requiring a page reload. Then you simply track the fragment, and when it changes, you go to the address specified by it.

+2
source

MVP GWT, Place . URL- #. , Gmail.

, gwt-presenter, DataPresenter DataPlace:

public class DataPlace extends ProvidedPresenterPlace<DataPresenter> {

@Inject
public DataPlace(Provider<DataPresenter> presenter) {
    super(presenter);
}

@Override
public String getName() {
    return "data";
}

@Override
protected void preparePresenter( PlaceRequest request, DataPresenter presenter ) {
    String state = request.getParameter("state", null);
    if (state != null) {
        // set the presenter state
        presenter.setState(State.valueOf(state));
    }
}

@Override
protected PlaceRequest prepareRequest( PlaceRequest request, DataPresenter presenter ) {
    return request.with("state", presenter.getState().toString());
}
}

URL- / # state = 12345, Place Presenter . Presenter. Place, .

+1

? . ActivityMapper. :

  • Change ActivityMapperso that it creates an instance Activityon the first call and returns that instance on subsequent calls. Or,

  • Use CachingActivityMapperto wrap yours ActivityMapper. He will return the existing one Activityinstead of creating a new one.

+1
source

Source: https://habr.com/ru/post/1779450/


All Articles