CDI alignment
JSF 2.2 starts CDI integration, provides built-in CDI compatible ViewScoped and @FlowScoped, and all CDI scopes are compatible with JSF.
In JSF 2.3, more CDI alignments are added.
A lots of JSF built-in facilities are exposed as CDI beans, and can be injected as general CDI beans.
In JSF 2.2, to get JSF facilities.
1
FacesContext context= FacesContext.getCurrentInstance();
2
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
3
Map<String, Object> cookieMap = FacesContext.getCurrentInstance().getExternalContext().getRequestCookieMap();
4
Map<String, Object> viewMap = FacesContext.getCurrentInstance().getViewRoot().getViewMap();
Copied!
In JSF 2.3, you can inject them directly in your backing bean.
1
@Inject
2
FacesContext facesContext;
3
4
@Inject
5
ExternalContext externalContext;
6
7
@Inject
8
@RequestCookieMap
9
Map<String, Object> cookieMap;
10
11
@Inject
12
@ViewMap
13
Map<String, Object> viewMap;
Copied!
And all of these can be resolved via EL in facelets template.
There is a table listed all supported facilities in Arjan Tijms's blog entry, What's new in JSF 2.3? .
Artifact
EL name
Qualifier
Type
Application
#{application}
-
java.lang.Object (javax.servlet.ServletContext)
ApplicationMap
#{applicationScope}
@ApplicationMap
java.util.Map
CompositeComponent
#{cc}
(Not injectable)
javax.faces.component.UIComponent
Component
#{component}
(Not injectable)
javax.faces.component.UIComponent
RequestCookieMap
#{cookie}
@RequestCookieMap
java.util.Map
FacesContext
#{facesContext}
-
javax.faces.context.FacesContext
Flash
#{flash}
-
javax.faces.context.Flash
FlowMap
#{flowScope}
@FlowMap
java.util.Map
HeaderMap
#{header}
@HeaderMap
java.util.Map
HeaderValuesMap
#{headerValues}
@HeaderValuesMap
java.util.Map
InitParameterMap
#{initParam}
@InitParameterMap
java.util.Map
RequestParameterMap
#{param}
@RequestParameterMap
java.util.Map
RequestParameterValuesMap
#{paramValues}
@RequestParameterValuesMap
java.util.Map
Request
#{request}
(Not injectable)
java.lang.Object (javax.servlet.http.HttpServletRequest)
RequestMap
#{requestScope}
@RequestMap
java.util.Map
ResourceHandler
#{"resource"}
-
javax.faces.application.ResourceHandler
Session
#{session}
(Not injectable)
java.lang.Object (javax.servlet.http.HttpSession)
SessionMap
#{sessionScope}
@SessionMap
java.util.Map
View
#{view}
-
javax.faces.component.UIViewRoot
ViewMap
#{viewScope}
@ViewMap
java.util.Map
ExternalContext
#{externalContext} (new)
-
javax.faces.context.ExternalContext
Last modified 8mo ago
Copy link