How to access JSF2 @ViewScoped beans through ExternalContext?

In JSF1, you can access bean instances of your current one FacesContexton

ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext()
ev.getApplicationMap().get(beanName) // get an @ApplicationScoped bean instance
ev.getSessionMap().get(beanName) // get a @SessionScoped bean instance
ev.getRequestMap().get(beanName) // get a @RequestScoped bean instance

JSF2 is @ViewScopedintroduced, but I can not find the appropriate method getViewMap()on ExternalContext? I am using the latest JSF 2.1.1-b04. I do not understand some aspects of the @ViewScopedbean? Is there another good practice for getting a @ViewScopedserver side bean instance ?

Thanks Steve

+3
source share
2 answers

Try expressing an expression ( evaluateExpressionGet ):

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

All Articles