【问题标题】:JSF Trouble with beans (scope)bean 的 JSF 问题(范围)
【发布时间】:2014-12-18 21:31:46
【问题描述】:

所以我正在测试我的 JSF 应用程序,突然我无法再提取存储在 bean 中的值了。我从 Request 范围切换到 Session 范围,并且能够提取一个值,但它似乎是我单击的最后一页的值。

文件结构如下: About.xhtml 设置存储在 Bean 上的页码,然后调用 Layout.xhtml,后者调用 Bean.Method() 以获取 Content_About.xhtml 以根据 About.xhtml 文件中声明的页码将一些文本加载到页面。

据我了解,只要我不需要在页面加载后访问存储的信息,请求范围就应该工作,但它的行为就像没有设置页码一样。

声明 Session 范围后,它会加载文本,但看起来好像是在构建页面,然后更改 bean 中存储的值。它要求我在我想要的页面上单击两次才能获得页面上的正确信息。

任何帮助表示赞赏。

进一步调查:我能够执行以下操作,但它在加载内容的方法调用前后显示了正确的页码。

Page Number: #{MainBean.getPage()}
<h:form>
<ui:include src="#{MainBean.Content()}"></ui:include>
</h:form>
Page Number: #{MainBean.getPage()}

【问题讨论】:

  • 我正在使用 Netbeans (IDE 6.9.1) 和 glassfish 3 进行部署。

标签: jsf session scope request javabeans


【解决方案1】:

接受首先构建 ui,使用存储变量的默认值,然后在调用布局时在 ui 声明中设置值。

我有类似的东西:

#{MainBean.setLevel(0)}
#{MainBean.setPage(1)}
<ui:include src="Layout.xhtml"></ui:include>

并将其更改为:

    <ui:include src="#{MainBean.setLayout(0,1)}"></ui:include>

public String setLayout(int lvl, int pg)
    {
        setLevel(lvl);
        setPage(pg);

        return GetPath()+"Layout.xhtml";
    }

这允许在构建 ui 期间设置 bean 的变量,并在请求的其余部分继续执行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-11
    • 2011-08-15
    • 2011-10-17
    • 1970-01-01
    • 2011-07-28
    • 2012-10-11
    • 2013-12-12
    相关资源
    最近更新 更多