Hello everyone,
we have been using the Vaadin Navigator API for a long time now. It’s nice, clean and simple, however we would like our views to be able to prevent navigating into them or away from them, depending on their current internal state. For example, if a user edits some text field and the new value is invalid, we don’t want to allow him to navigate away from the view and leave the text field in an invalid state (the click actions of our menu bar that trigger the actual navigation are not within the control of our views). Instead, if he tries to navigate away, we would like to display an error message (“hey, fix that before you leave!”). We would like to be able to implement a callback method “boolean canEnterView(View previous)” and “boolean canExitView(View next)” in each view that allows the view to specify if entering / exiting the view is currently allowed or not.
However, since there is no “View getView(String navigationState)” method in Vaadin’s Navigator class, and the corresponding collections that hold the providers are private (and not protected which prevents effective subclassing), we cannot write a wrapper Navigator (or subclass) that would respect these callback methods mentioned earlier.
Any suggestions on how to do this? I’m pretty sure that we are not the first people to encounter this problem.
Thanks,
Martin
EDIT: By coincidence, I’ve stumbled across the solution. It’s outlined here:
https://vaadin.com/wiki/-/wiki/Main/Access+control+for+views
. The key is that each ViewChangeListener can veto a view change. This is a little counter-intuitive because the usual semantics of a listener is that it merely reacts upon a change, but has no way to prevent it from happening. But we’ll do it that way since it seems to be the “Vaadin Style” to do it.