Preserve View State in Vaadin only in specific cases

Viewed 124

So, I have a view which should preserve the state when a user reloads. This is easy to do and well documented. However, in one case I reload the page from the server side after the user performs a specific action in which case I would actually want the view to completely reload.

Is there a way to differentiate between those cases and influence when the view should preserve its state?

1 Answers

In Vaadin 14 you can annotate specific views / components with @PreserveOnRefresh annotation. So if you have two views in your app like following, the RegularView will not be refreshed on reload.

@Route("preserve")
@PreserveOnRefresh
public class PreservedView extends VerticalLayout {

    public PreservedView() {
        // ...
    }
}

@Route("regular")
public class RegularView extends VerticalLayout {

    public RegularView () {
        // ...
    }
}
Related