spring icon indicating copy to clipboard operation
spring copied to clipboard

ViewScope broken when navigating from "foo" to "foo/123"

Open Artur- opened this issue 7 years ago • 1 comments

When navigating to the active view but with different parameters, a new view instance is created but put into newViewBeanStore in DefaultViewCache. The new bean store should be taken into use when viewActivated is called, but this method is never called as SpringNavigator never fires a view deactivation event for the old view, nor a view activation event for the new one. Why? Because SpringNavigator.switchView checks boolean viewNameChanged = !viewName.equals(currentViewName); and does nothing if the view name does not change - for whatever reason (it still calls super so it seems that it agrees that we are switching views but does not emit events).

End result of navigating from the active "foo" view to "foo/123"

  • The old FooView instance remains and is referred to by the view scope
  • A new FooView instance has been created and attached to the ViewDisplay
  • If you have an event bus or similar, the events end up in the old FooView instance as this one is in the bean store used by DefaultViewCache -> UI is not updated as expected because you update the old instance and not the new one

Possibly the same also happens if you just navigate to the active view without any parameter change.

Artur- avatar May 21 '17 19:05 Artur-

Any ideas why the view name comparison is there @hesara ?

Artur- avatar May 22 '17 09:05 Artur-