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

查看:21
本文介绍了视图范围 bean 在导航 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 在回发到 same 视图后仍然存在.当用于 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 action 方法中返回 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.

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

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