简体   繁体   English

具有Ajax更新的JSF selectOneButton-调用setter 2次

[英]JSF selectOneButton with ajax update - setter 2 times invoked

I use Primefaces 3.2 with ApacheMyfaces on WebSphere Application Server 8. 我在WebSphere Application Server 8上将Primefaces 3.2与ApacheMyfaces一起使用。

I have a selectOneButton with an ajax update inside. 我有一个带有ajax更新的selectOneButton。 When I switch the button, my setter firsts sets the value (int) to 0 and then to the value which is selected: 当我切换按钮时,我的设置器首先将值(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 is another selectComponent inside my form (optform). datecol是表单(optform)中的另一个selectComponent。

Why does JSF first set the value to 0 and then to eg 2? 为什么JSF首先将值设置为0,然后再设置为2?

SOLUTION It is a PrimeFaces selectOneButton Bug. 解决方案:这是PrimeFaces selectOneButton错误。 See My question here . 在这里看到我的问题。

Best Regards Veote 最好的问候

Likely what you are seeing is that the managed bean graph is being instantiated early in the JSF lifecycle, and only later in the APPLY_REQUEST_VALUES phase is the appropriate value being set for the managed property view . 您可能看到的是,在JSF生命周期的早期就实例化了托管bean graph ,只有在APPLY_REQUEST_VALUES阶段的后期才为托管属性view设置适当的值。 The managed bean regardless of scope, will be reinstantiated after each request due to the inherently stateless nature of the web. 由于Web固有的无状态性质,无论范围如何,托管Bean都会在每次请求后重新实例化。

For more information, BalusC has a great article on debugging the JSF Lifecycle with a step-by-step walkthrough on how to implement a custom PhaseListener that will help you understand and debug behavior like this in your application. 有关更多信息,B​​alusC上有一篇很棒的文章,介绍如何调试JSF Lifecycle,并分步介绍了如何实现自定义PhaseListener,该自定义阶段监听器将帮助您了解和调试应用程序中的此类行为。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM