gpt4 book ai didi

JSF 2 ViewScope 问题

转载 作者:行者123 更新时间:2023-12-04 01:01:10 25 4
gpt4 key购买 nike

引自此 nice article ,

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.



这些问题浮现在脑海中:
  • 如果我目前的观点是 index.xhtml ,如果我明确指定 return "index";<h:commandButton action="index.xhtml" ..> ,这基本上是返回到相同的 View ,bean 将再次重新创建.. 为什么?
  • viewscoped bean 可以在重定向后存活吗?
  • 如果可以,我该如何指定?我无法想象做这样的事情 return "?faces-redirect=true"<h:commandButton action="?faces-redirect=true" ..> ,是的,我想跳过定义 faces-config.xml 中的导航。使用 <redirect/> .
  • 最佳答案

    If my current view is index.xhtml, and if i specify explicitly return "index"; or , which is basically returning to the same view, the bean will be recreated again .. why ?



    如果您明确指定结果(阅读: View ),则会创建一个新 View 。您必须从 action 方法中返回 null 或 void(或者只是省略命令组件的 action 属性)。

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

    Can a Viewscoped bean survive a redirection ?



    否。只有 session 范围的 bean 可以和 flash scope 中的对象也(在重定向完成后立即结束,这可能是您在问这个问题时真正需要的功能要求)。

    关于JSF 2 ViewScope 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5494950/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com