JSF 1.2: How to keep request scoped managed bean alive across postbacks on same view?

时光毁灭记忆、已成空白 提交于 2019-11-27 04:51:57
BalusC

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

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

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

RichFaces <a4j:keepAlive> does also the same:

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

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 {
    // ...
}

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.

See also:

Not really, unless you store the Bean somewhere e.g. a Map in application scope, to retrieve it later.

Why not just make it Session scoped? This is what Session scope is there for, so multiple Requests during the same Session can hit the same state.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!