即使ManagedBean已经被实例化@PostConstruct方法被调用(例如,在AJAX的调用) [英] @PostConstruct method is called even if the ManagedBean has already been instantiated (e.g. on AJAX-calls)

查看:519
本文介绍了即使ManagedBean已经被实例化@PostConstruct方法被调用(例如,在AJAX的调用)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个@ViewScope ManagedBean和@PostConstruct初始化方法。创建一个新的实例时,此方法被调用,同时也对每一个AJAX调用。为什么会这样?

I have a @ViewScope ManagedBean and a @PostConstruct initialisation method. This method is called when a new instance is created, but also on every ajax call. Why is this so?

在一个AJAX调用init-方法被调用和执行,但没有改变可见。例如,如果我在init-方法更改属性,这只是对instatiation和不可见的AJAX调用。对于AJAX的调用值的变化是不是永久性的@ViewScoped豆。

On an AJAX-call the init-Method is called and executed, but no changes are visible. For example if I change a property in the init-Method, this is only visible on instatiation and not for AJAX-calls. For AJAX-calls the value change is not persistent in the @ViewScoped Bean.

谁能告诉为什么会这样?我怎样才能改变呢?

Can anyone tell why this is so? How can I change this?

推荐答案

这是不正常的行为。如果您绑定标签处理器的属性或 JSF组件到视图的属性绑定属性范围的bean,而部分国家储蓄开启时会发生这种情况。这就是所谓的问题1492 其固定在(即将到来的)Mojarra 2.2。

This is not normal behavior. This will happen if you bind tag handler attributes or the binding attribute of JSF components to a property of a view scoped bean while partial state saving is turned on. This is known as issue 1492 which is fixed in (the upcoming) Mojarra 2.2.

在一般情况下,可以通过在缺乏渲染属性识别标记处理程序。例如。 c为C:如果> < F:验证> <用户界面:包括> 等,如果你绑定这样的标签处理器的属性视图的属性范围的bean像如下

In general, you can recognize tag handlers by the lack of the rendered attribute. E.g. <c:if>, <f:validator>, <ui:include>, etc. If you bind an attribute of such a tag handler to a property of the view scoped bean like follows

<c:if test="#{viewScopedBean.something}"></c:if>
<h:inputText><f:validator binding="#{viewScopedBean.validate}" /></h:inputText>
<ui:include src="#{viewScopedBean.includePage}" />

那么该视图范围的bean将每次重建的观点是从部分保存的状态恢复。这是一个鸡生蛋蛋问题的看法范围内,因为这样才能获得的右键的看法范围的bean,就必须从恢复的视图中提取。

then the view scoped bean will be recreated everytime the view is to be restored from a partially saved state. This is a chicken-egg issue with the view scope, because in order to get the right view scoped bean, it has to be extracted from the restored view.

如果您引用视图的属性在JSF组件的结合属性范围的bean这也将发生。

This will also happen if you reference a property of a view scoped bean in the binding attribute of a JSF component.

<h:someComponent binding="#{viewScopedBean.someComponent}" />

参见:

  • <一个href="http://balusc.blogspot.com/2011/09/communication-in-jsf-20.html#ViewScopedFailsInTagHandlers">Communication在JSF 2.0 - @ViewScoped 失败的标记处理程序
  • See also:

    • Communication in JSF 2.0 - @ViewScoped fails in tag handlers
    • 这篇关于即使ManagedBean已经被实例化@PostConstruct方法被调用(例如,在AJAX的调用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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