视图范围bean是否在Navigation JSF中存活 [英] Does view scope bean survive Navigation JSF

查看:70
本文介绍了视图范围bean是否在Navigation JSF中存活的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对视图范围感到很困惑.我以为它可以在JSF导航到另一个页面(显然没有重定向)中幸免于难,但事实并非如此.那么,使用它代替请求范围的好处是什么,如果我召唤相同的视图,它将是相同的对象?

I am quite confused with the view scope. I thought it could survive a JSF navigation to another page (no redirect, obviously), but it doesn't. So what's the advantage to use it instead of request scope, that if i summoned the same view it will be the same object?

推荐答案

优点是该bean可以在回发到相同视图的情况下幸免.当在rendered属性中使用或作为h:dataTable的模型或用作隐藏输入等时,您不再需要自己保留任何数据.过去,很多黑客用于解决此问题.

The advantage is that the bean survives postbacks to the same view. You don't need to preserve any data yourself anymore when used in rendered attributes or as model for h:dataTable or as hidden inputs, etcetera. In the past, a lot of hacks were been used to go around this.

只要您与相同视图交互(即您在bean操作方法中返回voidnull),视图作用域的bean就会一直存在.当您导航到另一个视图时,例如通过单击链接或返回不同的操作结果,然后在渲染响应结束时将视图作用域的Bean丢弃,并且在下一个请求中将不可用.

A view scoped bean lives as long as you interact with the same view (i.e. you return void or null in bean action method). When you navigate away to another view, e.g. by clicking a link or by returning a different action outcome, then the view scoped bean will be trashed by end of render response and not be available in the next request.

  • Benefits and pitfalls of @ViewScoped
  • Any disadvantages of JSF 2.0?

这篇关于视图范围bean是否在Navigation JSF中存活的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆