Michał Bendowski
Michał Bendowski

Reputation: 2791

In GWT MVP, how to save state in the URL, without navigating to another place?

I have a simple page, with a small form and a table for results. When the user clicks the "Search" button, I'd like the form contents to saved in the URL, so that the search is "bookmarkable". So what I would really like to do is to update the URL (place) without triggering the whole MVP machinery (my current activity can handle the new place without restarting).

How can I do that? I tried to mess with the History class directly, but then the back button behave strangely. Looking at SO I found out about the CachingActivityMapper, but I'm not sure whether that's the "right" approach.

Upvotes: 3

Views: 523

Answers (1)

Thomas Broyer
Thomas Broyer

Reputation: 64541

CachingActivityMapper (or anything similar) is the right approach.

The thing is, if an ActivityMapper returns the same instance (really the same, not even an instance that compares equals()) as the current activity, then the ActivityManager does nothing (particularly, doesn't restart the activity).

Note however that it really does nothing, so your activity will have to listen to PlaceChangeEvents ti be notified of the change (or your ActivityMapper could "notify" it before returning it to the ActivityManager; this is basically the approach taken by the Expenses sample, where activities are singletons, and the ActivityMappers calls setPlace on them).

Upvotes: 5

Related Questions