Spring session-scoped beans (controllers) and references to services, in terms of serialization

前端 未结 6 1151
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-27 12:44
  • a standard case - you have a controller (@Controller) with @Scope(\"session\").
  • classes put in the session usually are expected to i
6条回答
  •  死守一世寂寞
    2020-11-27 12:54

    I recently combined JSF with Spring. I use RichFaces and the @KeepAlive feature, which serializes the JSF bean backing the page. There are two ways I have gotten this to work.

    1) Use @Component("session") on the JSF backing bean

    2) Get the bean from ELContext when ever you need it, something like this:

    @SuppressWarnings("unchecked")
    public static  T  getBean(String beanName) {
        return (T) FacesContext.getCurrentInstance().getApplication().getELResolver().getValue(FacesContext.getCurrentInstance().getELContext(), null, beanName);
    }
    

提交回复
热议问题