JSF 1.2:如何在同一视图上的回发之间保持请求范围的托管 bean 处于活动状态? [英] JSF 1.2: How to keep request scoped managed bean alive across postbacks on same view?

查看:14
本文介绍了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.

您可以使用 Tomahawk <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> 也一样:

<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.

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

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