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

前端 未结 2 2040
清歌不尽
清歌不尽 2020-11-30 10:23

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

The general problem is, as the bean gets trashed on end of request and recreat

2条回答
  •  长情又很酷
    2020-11-30 11:06

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

    You can do it using Tomahawk . Add the following line somewhere to the page:

    
    

    RichFaces does also the same:

    
    

    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:

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

提交回复
热议问题