在视图之间导航时,如何保留vaadin视图实例

发布于 2025-01-20 17:32:30 字数 202 浏览 4 评论 0原文

我有一个包含大量数据的视图。数据在视图初始化时加载。现在,当我使用 Router 离开视图然后返回视图时,会创建一个新的视图实例,从而触发重新获取所有数据。即使返回视图时,我也想保留原始视图实例 - 如何实现?

编辑: 添加细节,这是一个 Spring Boot 应用程序,与我的预期不同,将视图注释为 @UIScope 并没有保留实例,但每次导航到视图时都会创建一个新实例。

I have a view which is quite heavy with data. The data is loaded when the view is initialized. Now, when I navigate away from the view using Router and then return to the view, a new view instance is created triggering refetching of all the data. I would like to preserve the original view instance even when returning to the view - how can this be achieved?

Edit:
To add details, this is a Spring Boot application and unlike to my expectation, annotating a view as @UIScope didn't keep the instance, but a new instance was created every time when navigating to the view.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

总攻大人 2025-01-27 17:32:30

如果有人遇到相同的情况,请回答我自己的问题。

我有一个Spring Boot应用程序,因此第一步是定义视图的范围,以免重新创建它们,合适的范围是Uiscope。但是,这还不够,即使注入豆类在框外工作,默认情况下,视图似乎并不是管理bean,因此将@component注释添加到视图中使它们受到管理,因此, @ @ @ Uiscope范围也开始工作。

@UIScope
@PreserveOnRefresh
@PageTitle("example")
@Route(value = "example", layout = MainLayout.class)
@Component
public class ExampleView extends VerticalLayout {

Answering my own question, in case someone else runs into the same situation.

I had a Spring Boot application, so the first step was to define the scope for the views so that they wouldn't be recreated, a suitable scope is UIScope. However, that is not enough, even though injecting of beans work out-of-the-box, the views don't seem to be managed beans by default, so adding @Component annotation to the view makes them managed and thus, the @UIScope scoping also starts working.

@UIScope
@PreserveOnRefresh
@PageTitle("example")
@Route(value = "example", layout = MainLayout.class)
@Component
public class ExampleView extends VerticalLayout {
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文