开发者

Howto access JSF2 @ViewScoped beans via ExternalContext?

开发者 https://www.devze.com 2023-03-06 08:49 出处:网络
In JSF1 you can access the bean instances of your current FacesContext by ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext()

In JSF1 you can access the bean instances of your current FacesContext by

ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext()
ev.getApplicationMap().get(beanName) // get an @ApplicationScoped bean instance
ev.getSessionMap().get(bean开发者_C百科Name) // get a @SessionScoped bean instance
ev.getRequestMap().get(beanName) // get a @RequestScoped bean instance

In JSF2 @ViewScoped has been introduced, but I can't find a corresponding getViewMap() method on ExternalContext? I am using latest JSF 2.1.1-b04. Am i misunderstanding some aspects of a @ViewScoped bean? Is there another good-practice to get a @ViewScoped bean instance on the server side?

Thanks, Steve


Try to eval expression (evaluateExpressionGet):

context.getApplication().evaluateExpressionGet(context, "#{beanName}", BeanClass.class)


View scoped data is stored in the view root. You can get this from the context.

0

精彩评论

暂无评论...
验证码 换一张
取 消