0

In Vaadin Flow, Once a view is rendered, another invocation of the same view again will render the previously opened view. Is their any way to create new instance of the class.


this is my view page which am talking about. It doesnt have route.

enter image description here


On Clicking the View Icon this code is being executed, the route is always dynamically assigned. View Page is IBillingViewPageUI

enter image description here


The View Icon

enter image description here


enter image description here


enter image description here

Here once once view icon is clicked, the page will be rendered with required data. but clicking on another view icon, since the navigation target is same, same instance is being opened again. no new instances are created. so my dynamic data rendering is not getting possible.

Anna Koskinen
  • 1,362
  • 3
  • 22
  • Please add the code you have tried and how it failed (e.g. errors, stacktraces, logs, ...) so we can improve on it. – cfrick Jun 13 '21 at 09:13
  • What do you call by a "view"? Is it a `@Route` annotated class? Because when navigating to these routes, the construcor is called each time. – Hawk Jun 13 '21 at 19:59

1 Answers1

1

By default, each view in Vaadin Flow will be recreated each time when you navigate to it. If you want to maintain the state of the views across the UI lifetime (remain the same in a single browser tab), you need to either use the Spring add-on and make the view a @Component in @UIScope, the CDI add-on and similar, or create and register a custom Instantiator if you're using neither.

ollitietavainen
  • 3,900
  • 13
  • 30
  • Hi ollitietavainen, my doubt is like, I have a view page for every screen. I am trying to maintain a single view page, like a template. Suppose my view page is MainViewPageUi. it will be invoked on click of every view page links. the navigation target is MainViewPageUi. But routes will be dynamically assigned as per the link clicked. The routes will never be the same. But the issue is once a view link is clicked. clicking on other links will open copy of this page same content but routes are different. Doesnt enter constructor. so object instances are the same. i want to render different data. – Sangeeth S Kumar Jun 17 '21 at 11:11
  • Sounds like you need to update your question with more information and code examples because your description doesn't yet cover what exactly is happening. – ollitietavainen Jun 18 '21 at 06:01
  • Hi ollitietavainen, I had updated the question with code and images, i suppose its clear now. – Sangeeth S Kumar Jun 19 '21 at 07:33
  • At least one problem is that you're registering the route in the click listener of the menu item, which is too late if you want to navigate on the first click. Some recommendations: 1) use text instead of images for code 2) split your problem into smaller parts – ollitietavainen Jun 21 '21 at 13:35