【问题标题】:JSF selectOneButton with ajax update - setter 2 times invoked带有 ajax 更新的 JSF selectOneButton - 调用了 2 次 setter
【发布时间】:2012-07-15 00:02:32
【问题描述】:

我在 WebSphere Application Server 8 上使用 Primefaces 3.2 和 ApacheMyfaces。

我有一个内部带有 ajax 更新的 selectOneButton。 当我切换按钮时,我的设置器首先将值 (int) 设置为 0,然后设置为选定的值:

<p:selectOneButton value="#{graph.view}" id="view">
    <f:selectItem itemLabel="W" itemValue="1" />
    <f:selectItem itemLabel="M" itemValue="2" />
    <f:selectItem itemLabel="Y" itemValue="3" />
    <p:ajax event="change" update=":optform:datecol"/>
</p:selectOneButton>

datecol 是我表单中的另一个 selectComponent (optform)。

为什么 JSF 首先将值设置为 0,然后再设置为 e.g. 2?

解决方案 这是一个 PrimeFaces selectOneButton 错误。请参阅我的问题here

最好的问候 投票

【问题讨论】:

    标签: java ajax jsf-2 primefaces


    【解决方案1】:

    您所看到的可能是托管 bean graph 在 JSF 生命周期的早期被实例化,并且仅在 APPLY_REQUEST_VALUES 阶段的后期才为托管属性 view 设置适当的值。由于 Web 固有的无状态特性,托管 bean 无论范围如何,都会在每次请求后重新实例化。

    有关更多信息,B​​alusC 有一篇关于调试 JSF 生命周期的精彩文章,其中分步介绍了如何实现自定义 PhaseListener,这将帮助您理解和调试应用程序中的此类行为。

    http://balusc.blogspot.com/2006/09/debug-jsf-lifecycle.html

    【讨论】:

    • 这帮我找到了原因!谢谢:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-21
    • 1970-01-01
    • 2012-03-21
    • 2017-12-15
    • 2015-04-24
    • 1970-01-01
    相关资源
    最近更新 更多