在 GWT MVP 中,如何在 URL 中保存状态,而不导航到另一个地方?
我有一个简单的页面,带有一个小表单和一个结果表。当用户单击“搜索”按钮时,我希望将表单内容保存在 URL 中,以便搜索“可添加书签”。所以我真正想做的是更新 URL(地点)而不触发整个 MVP 机制(我当前的活动可以处理新地点而无需重新启动)。
我怎样才能做到这一点?我试图直接扰乱 History 类,但后退按钮的行为很奇怪。看着 SO,我发现了 CachingActivityMapper,但我不确定这是否是“正确”的方法。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
CachingActivityMapper(或类似的东西)是正确的方法。
问题是,如果 ActivityMapper 返回与当前 Activity 相同的实例(实际上是相同的,甚至不是比较 equals() 的实例),那么 ActivityManager 不会执行任何操作(特别是不会重新启动)活动)。
但请注意,它实际上什么都不做,因此您的 Activity 必须监听 PlaceChangeEvent 才能收到更改通知(或者您的 ActivityMapper 可以在返回之前“通知”它)到 ActivityManager;这基本上是 Expenses 示例所采用的方法,其中活动是单例,并且 ActivityMappers 对它们调用
setPlace
)。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
PlaceChangeEvent
s 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 callssetPlace
on them).