JSF 2 ViewScope问题 [英] JSF 2 ViewScope questions

查看:63
本文介绍了JSF 2 ViewScope问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

引用此不错的文章

新视图范围应解决 正是那些问题. @ViewScoped 只要你 提交表单到同一视图 一次又一次.换句话说,如 只要采取行动方法 返回null或什至void,该bean 将在下一个请求中出现. 导航到其他视图后, 那么豆将被丢弃.

The new view scope should solve exactly those issues. A @ViewScoped bean will live as long as you're submitting the form to the same view again and again. In other words, as long as when the action method(s) returns null or even void, the bean will be there in the next request. Once you navigate to a different view, then the bean will be trashed.

这些问题浮现在脑海:

  1. 如果我当前的视图是index.xhtml,并且如果我明确指定了return "index";<h:commandButton action="index.xhtml" ..>(基本上返回相同的视图),那么将再次重新创建Bean.为什么?
  2. 可观察范围的bean能否在重定向中幸存?
  3. 如果可以的话,如何指定呢?我无法想象要做return "?faces-redirect=true"<h:commandButton action="?faces-redirect=true" ..>之类的事情,是的,我想跳过使用<redirect/>faces-config.xml中定义导航的方法.
  1. If my current view is index.xhtml, and if I specify explicitly return "index"; or <h:commandButton action="index.xhtml" ..>, which is basically returning to the same view, the bean will be recreated again .. why?
  2. Can a viewscoped bean survive a redirection?
  3. And if it can, how can I specify it? I can't imagine doing something like return "?faces-redirect=true" or <h:commandButton action="?faces-redirect=true" ..>, and yes, I would like to skip defining the navigation in faces-config.xml using the <redirect/>.

推荐答案

如果我当前的视图是index.xhtml,并且如果我明确指定返回"index";或,基本上返回到相同的视图,或者将再次重新创建该bean ..为什么?

如果您明确指定结果(读取:视图),则将创建一个新视图.您必须从action方法中返回null或void(或者只保留命令组件的action属性).

If you explicitly specify an outcome (read: a view), then a new view will be created. You have to return null or void from the action method (or just leave out the action attribute of the command component).

我必须承认,我理解您的困惑,并且根据上下文可以对视图"一词进行不同的解释.我想迟早会修改链接文章中的措词.

I must admit that I understand your confusion and that the term "view" can be interpreted differently, depending on the context. I think I'll revise the wording in the linked article sooner or later.

Viewscoped Bean能否在重定向中幸存?

不.也只有会话作用域的bean可以和 Flash作用域中的对象(其中重定向完成后立即结束,这也许是您实际上对提出此问题时所想到的功能要求的需要.

No. Only session scoped beans can and objects in the flash scope also (which ends immediately once the redirect has been finished, that's maybe which you actually need for the functional requirement you had in mind when asking this question).

这篇关于JSF 2 ViewScope问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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