Seam 中静态变量的范围
如果我在具有页面范围的类中定义静态变量,那么静态变量的范围是什么?即使我离开该页面然后返回该页面(这里的页面是指我引用静态变量的 xhtml 页面),它是否会保留数据?
If I define a static variable in a class having Page Scope, then what will be the Scope of the Static Variable? Will it persist the data even if I navigate away from that page and then come back to that page(here by page I mean the xhtml page on which I am referring to the static variable)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
静态字段与类相关联,而不是与任何对象相关联。 Seam Scopes 不会改变静态的含义。页面上下文允许您将状态与特定
实例
相关联,但如果您为静态字段分配一个值,则无论您的Seam Scope如何,该值都将由所有实例共享。是的,由于您的 Web 应用程序有一个类加载器,因此静态变量的范围应该大于页面范围。
Static fields are associated with the class, rather than with any object. Seam Scopes don't change the meaning of static. The page context allows you to associate state with a particular
instance
, but if you assign a value to a static field that value will be share by all instances regardless of your Seam Scope.Yes, since you have one classloader for your web application, the scope of your static variable should be more than page scope.