本文介绍了JSF 1.2:如何使请求范围内的受管Bean在同一视图上的回发之间保持活动状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使请求范围内的bean在同一页面上的回发之间保持活动状态?

Is it possible to keep a request scoped bean alive across postbacks on the same page?

一般的问题是,随着Bean在请求结束时被丢弃并在每个表单提交时重新创建,例如,动态操纵的disabledreadonlyrendered后面的布尔值被重置为其默认值并导致表单不再按预期工作.

The general problem is, as the bean gets trashed on end of request and recreated on every form submit, for example the booleans behind dynamically manipulated disabled, readonly and rendered get reset to their default values and cause the forms to not work as intented anymore.

推荐答案

我假设会话范围不是 选项,否则这个问题就没有意义了.

I'll assume that the session scope is not an option, otherwise this question makes little sense.

您可以使用战斧<t:saveState> .将以下行添加到页面的某处:

You can do it using Tomahawk <t:saveState>. Add the following line somewhere to the page:

<t:saveState value="#{bean}" />

RichFaces <a4j:keepAlive> 也会一样:

RichFaces <a4j:keepAlive> does also the same:

<a4j:keepAlive beanName="#{bean}" />

或者,如果有空间,请升级到至少JSF 2.x,然后将bean置于 view 范围内:

Or if there is room, upgrade to at least JSF 2.x and put the bean in view scope:

@ManagedBean
@ViewScoped
public class Bean implements Serializable {
    // ...
}

无论采用哪种方式,当您回发到同一视图并继续从操作方法返回nullvoid时,都将在同一个bean中.

Regardless of the way, the same bean will be there when you postback to the same view and keep returning null or void from action methods.

  • How to choose the right bean scope?
  • Difference between View and Request scope in managed beans

这篇关于JSF 1.2:如何使请求范围内的受管Bean在同一视图上的回发之间保持活动状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 06:19