Class FacesLocal
- java.lang.Object
-
- org.omnifaces.util.FacesLocal
-
public final class FacesLocal extends Object
Collection of utility methods for the Faces API that are mainly shortcuts for obtaining stuff from the provided
FacesContext
argument. In effect, it 'flattens' the hierarchy of nested objects.The difference with
Faces
is that no one method ofFacesLocal
obtains theFacesContext
from the current thread byFacesContext.getCurrentInstance()
. This job is up to the caller. This is more efficient in situations where multiple utility methods needs to be called at the same time. InvokingFacesContext.getCurrentInstance()
is at its own an extremely cheap operation, however as it's to be obtained as aThreadLocal
variable, it's during the call still blocking all other running threads for some nanoseconds or so.Note that methods which are directly available on
FacesContext
instance itself, such asFacesContext.getExternalContext()
,FacesContext.getViewRoot()
,FacesContext.isValidationFailed()
, etc are not delegated by the this utility class, because it would design technically not make any sense to delegate a single-depth method call like follows:ExternalContext externalContext = FacesLocal.getExternalContext(facesContext);
instead of just calling it directly like follows:
ExternalContext externalContext = facesContext.getExternalContext();
Usage
Some examples (for the full list, check the API documentation):
FacesContext context = Faces.getContext(); User user = FacesLocal.getSessionAttribute(context, "user"); Item item = FacesLocal.evaluateExpressionGet(context, "#{item}"); String cookieValue = FacesLocal.getRequestCookie(context, "cookieName"); List<Locale> supportedLocales = FacesLocal.getSupportedLocales(context); FacesLocal.invalidateSession(context); FacesLocal.redirect(context, "login.xhtml");
- Since:
- 1.6
- Author:
- Arjan Tijms, Bauke Scholtz
- See Also:
Servlets
-
-
Method Summary
-
-
-
Method Detail
-
getPackage
public static Package getPackage(FacesContext context)
- See Also:
Faces.getPackage()
-
getImplInfo
public static String getImplInfo(FacesContext context)
- See Also:
Faces.getImplInfo()
-
getServerInfo
public static String getServerInfo(FacesContext context)
- See Also:
Faces.getServerInfo()
-
getProjectStage
public static ProjectStage getProjectStage(FacesContext context)
- See Also:
Faces.getProjectStage()
-
isDevelopment
public static boolean isDevelopment(FacesContext context)
- See Also:
Faces.isDevelopment()
-
isSystemTest
public static boolean isSystemTest(FacesContext context)
- See Also:
Faces.isSystemTest()
-
isProduction
public static boolean isProduction(FacesContext context)
- See Also:
Faces.isProduction()
-
getMapping
public static String getMapping(FacesContext context)
- See Also:
Faces.getMapping()
-
isPrefixMapping
public static boolean isPrefixMapping(FacesContext context)
- See Also:
Faces.isPrefixMapping()
-
evaluateExpressionGet
public static <T> T evaluateExpressionGet(FacesContext context, String expression)
- See Also:
Faces.evaluateExpressionGet(String)
-
evaluateExpressionSet
public static void evaluateExpressionSet(FacesContext context, String expression, Object value)
-
resolveExpressionGet
public static <T> T resolveExpressionGet(FacesContext context, Object base, String property)
-
resolveExpressionSet
public static void resolveExpressionSet(FacesContext context, Object base, String property, Object value)
-
getContextAttribute
public static <T> T getContextAttribute(FacesContext context, String name)
- See Also:
Faces.getContextAttribute(String)
-
getContextAttribute
public static <T> T getContextAttribute(FacesContext context, String name, Supplier<T> computeIfAbsent)
-
setContextAttribute
public static void setContextAttribute(FacesContext context, String name, Object value)
-
createConverter
public static <T> Converter<T> createConverter(FacesContext context, Object identifier)
- See Also:
Faces.createConverter(Object)
-
createConverter
public static <T> Converter<T> createConverter(FacesContext context, String identifier)
- See Also:
Faces.createConverter(String)
-
createConverter
public static <T> Converter<T> createConverter(FacesContext context, Class<?> identifier)
- See Also:
Faces.createConverter(Class)
-
createValidator
public static <T> Validator<T> createValidator(FacesContext context, Object identifier)
- See Also:
Faces.createValidator(Object)
-
createValidator
public static <T> Validator<T> createValidator(FacesContext context, String identifier)
- See Also:
Faces.createValidator(String)
-
createValidator
public static <T> Validator<T> createValidator(FacesContext context, Class<?> identifier)
- See Also:
Faces.createValidator(Class)
-
createResource
public static Resource createResource(FacesContext context, String resourceName)
- See Also:
Faces.createResource(String)
-
createResource
public static Resource createResource(FacesContext context, String libraryName, String resourceName)
- See Also:
Faces.createResource(String, String)
-
createResource
public static Resource createResource(FacesContext context, ResourceIdentifier resourceIdentifier)
- See Also:
Faces.createResource(ResourceIdentifier)
-
getLifecycle
public static Lifecycle getLifecycle(FacesContext context)
- See Also:
Faces.getLifecycle()
-
setViewRoot
public static void setViewRoot(FacesContext context, String viewId)
- See Also:
Faces.setViewRoot(String)
-
getViewId
public static String getViewId(FacesContext context)
- See Also:
Faces.getViewId()
-
getViewIdWithParameters
public static String getViewIdWithParameters(FacesContext context)
- See Also:
Faces.getViewIdWithParameters()
-
getViewName
public static String getViewName(FacesContext context)
- See Also:
Faces.getViewName()
-
getViewDeclarationLanguage
public static ViewDeclarationLanguage getViewDeclarationLanguage(FacesContext context)
- See Also:
Faces.getViewDeclarationLanguage()
-
getRenderKit
public static RenderKit getRenderKit(FacesContext context)
- See Also:
Faces.getRenderKit()
-
normalizeViewId
public static String normalizeViewId(FacesContext context, String path)
- See Also:
Faces.normalizeViewId(String)
-
getViewParameters
public static Collection<UIViewParameter> getViewParameters(FacesContext context)
- See Also:
Faces.getViewParameters()
-
getViewParameterMap
public static Map<String,List<String>> getViewParameterMap(FacesContext context)
- See Also:
Faces.getViewParameterMap()
-
getHashParameters
public static Collection<HashParam> getHashParameters(FacesContext context)
- See Also:
Faces.getHashParameters()
-
getHashParameterMap
public static Map<String,List<String>> getHashParameterMap(FacesContext context)
- See Also:
Faces.getHashParameterMap()
-
getHashQueryString
public static String getHashQueryString(FacesContext context)
-
getScriptParameters
public static Collection<ScriptParam> getScriptParameters(FacesContext context)
- See Also:
Faces.getScriptParameters()
-
getMetadataAttributes
public static Map<String,Object> getMetadataAttributes(FacesContext context, String viewId)
- See Also:
Faces.getMetadataAttributes(String)
-
getMetadataAttributes
public static Map<String,Object> getMetadataAttributes(FacesContext context)
- See Also:
Faces.getMetadataAttributes()
-
getMetadataAttribute
public static <T> T getMetadataAttribute(FacesContext context, String viewId, String name)
-
getMetadataAttribute
public static <T> T getMetadataAttribute(FacesContext context, String name)
- See Also:
Faces.getMetadataAttribute(String)
-
getLocale
public static Locale getLocale(FacesContext context)
- See Also:
Faces.getLocale()
-
getDefaultLocale
public static Locale getDefaultLocale(FacesContext context)
- See Also:
Faces.getDefaultLocale()
-
getSupportedLocales
public static List<Locale> getSupportedLocales(FacesContext context)
- See Also:
Faces.getSupportedLocales()
-
setLocale
public static void setLocale(FacesContext context, Locale locale)
- See Also:
Faces.setLocale(Locale)
-
getMessageBundle
public static ResourceBundle getMessageBundle(FacesContext context)
- See Also:
Faces.getMessageBundle()
-
getResourceBundle
public static ResourceBundle getResourceBundle(FacesContext context, String var)
- See Also:
Faces.getResourceBundle(String)
-
getResourceBundles
public static Map<String,ResourceBundle> getResourceBundles(FacesContext context)
- See Also:
Faces.getResourceBundles()
-
getBundleString
public static String getBundleString(FacesContext context, String key)
- See Also:
Faces.getBundleString(String)
-
navigate
public static void navigate(FacesContext context, String outcome)
- See Also:
Faces.navigate(String)
-
getBookmarkableURL
public static String getBookmarkableURL(FacesContext context, Map<String,List<String>> params, boolean includeViewParams)
- See Also:
Faces.getBookmarkableURL(Map, boolean)
-
getBookmarkableURL
public static String getBookmarkableURL(FacesContext context, String viewId, Map<String,List<String>> params, boolean includeViewParams)
-
getBookmarkableURL
public static String getBookmarkableURL(FacesContext context, Collection<? extends ParamHolder<?>> params, boolean includeViewParams)
-
getBookmarkableURL
public static String getBookmarkableURL(FacesContext context, String viewId, Collection<? extends ParamHolder<?>> params, boolean includeViewParams)
-
getFaceletContext
public static FaceletContext getFaceletContext(FacesContext context)
- See Also:
Faces.getFaceletContext()
-
getFaceletAttribute
public static <T> T getFaceletAttribute(FacesContext context, String name)
- See Also:
Faces.getFaceletAttribute(String)
-
setFaceletAttribute
public static void setFaceletAttribute(FacesContext context, String name, Object value)
-
getRequest
public static HttpServletRequest getRequest(FacesContext context)
- See Also:
Faces.getRequest()
-
isAjaxRequest
public static boolean isAjaxRequest(FacesContext context)
- See Also:
Faces.isAjaxRequest()
-
isAjaxRequestWithPartialRendering
public static boolean isAjaxRequestWithPartialRendering(FacesContext context)
-
isPostback
public static boolean isPostback(FacesContext context)
- See Also:
Faces.isPostback()
-
getRequestParameterMap
public static Map<String,String> getRequestParameterMap(FacesContext context)
- See Also:
Faces.getRequestParameterMap()
-
getMutableRequestParameterMap
public static Map<String,List<String>> getMutableRequestParameterMap(FacesContext context)
- See Also:
Faces.getMutableRequestParameterMap()
-
getRequestParameter
public static String getRequestParameter(FacesContext context, String name)
- See Also:
Faces.getRequestParameter(String)
-
getRequestParameter
public static <T> T getRequestParameter(FacesContext context, String name, Class<T> type)
- See Also:
Faces.getRequestParameter(String, Class)
-
getRequestParameter
public static <T> T getRequestParameter(FacesContext context, String name, Function<String,T> converter)
-
getRequestParameter
public static <T> T getRequestParameter(FacesContext context, String name, Function<String,T> converter, Supplier<T> defaultValue)
-
getRequestParameterValuesMap
public static Map<String,String[]> getRequestParameterValuesMap(FacesContext context)
- See Also:
Faces.getRequestParameterValuesMap()
-
getRequestParameterValues
public static String[] getRequestParameterValues(FacesContext context, String name)
- See Also:
Faces.getRequestParameterValues(String)
-
getRequestParameterValues
public static <T> T[] getRequestParameterValues(FacesContext context, String name, Class<T> type)
-
getRequestParts
public static Collection<Part> getRequestParts(FacesContext context)
- See Also:
Faces.getRequestParts()
-
getRequestPart
public static Part getRequestPart(FacesContext context, String name)
- See Also:
Faces.getRequestPart(String)
-
getRequestParts
public static Collection<Part> getRequestParts(FacesContext context, String name)
- See Also:
Faces.getRequestParts(String)
-
getRequestHeaderMap
public static Map<String,String> getRequestHeaderMap(FacesContext context)
- See Also:
Faces.getRequestHeaderMap()
-
getMutableRequestHeaderMap
public static Map<String,List<String>> getMutableRequestHeaderMap(FacesContext context)
- See Also:
Faces.getMutableRequestHeaderMap()
-
getRequestHeader
public static String getRequestHeader(FacesContext context, String name)
- See Also:
Faces.getRequestHeader(String)
-
getRequestHeaderValuesMap
public static Map<String,String[]> getRequestHeaderValuesMap(FacesContext context)
- See Also:
Faces.getRequestHeaderValuesMap()
-
getRequestHeaderValues
public static String[] getRequestHeaderValues(FacesContext context, String name)
- See Also:
Faces.getRequestHeaderValues(String)
-
getRequestContextPath
public static String getRequestContextPath(FacesContext context)
- See Also:
Faces.getRequestContextPath()
-
getRequestServletPath
public static String getRequestServletPath(FacesContext context)
- See Also:
Faces.getRequestServletPath()
-
getRequestPathInfo
public static String getRequestPathInfo(FacesContext context)
- See Also:
Faces.getRequestPathInfo()
-
getRequestHostname
public static String getRequestHostname(FacesContext context)
- See Also:
Faces.getRequestHostname()
-
getRequestBaseURL
public static String getRequestBaseURL(FacesContext context)
- See Also:
Faces.getRequestBaseURL()
-
getRequestDomainURL
public static String getRequestDomainURL(FacesContext context)
- See Also:
Faces.getRequestDomainURL()
-
getRequestURL
public static String getRequestURL(FacesContext context)
- See Also:
Faces.getRequestURL()
-
getRequestURI
public static String getRequestURI(FacesContext context)
- See Also:
Faces.getRequestURI()
-
getRequestQueryString
public static String getRequestQueryString(FacesContext context)
- See Also:
Faces.getRequestQueryString()
-
getRequestQueryStringMap
public static Map<String,List<String>> getRequestQueryStringMap(FacesContext context)
- See Also:
Faces.getRequestQueryStringMap()
-
getRequestURLWithQueryString
public static String getRequestURLWithQueryString(FacesContext context)
- See Also:
Faces.getRequestURLWithQueryString()
-
getRequestURIWithQueryString
public static String getRequestURIWithQueryString(FacesContext context)
- See Also:
Faces.getRequestURIWithQueryString()
-
getRemoteAddr
public static String getRemoteAddr(FacesContext context)
- See Also:
Faces.getRemoteAddr()
-
getUserAgent
public static String getUserAgent(FacesContext context)
- See Also:
Faces.getUserAgent()
-
getReferrer
public static String getReferrer(FacesContext context)
- See Also:
Faces.getReferrer()
-
isRequestSecure
public static boolean isRequestSecure(FacesContext context)
- See Also:
Faces.isRequestSecure()
-
getResponse
public static HttpServletResponse getResponse(FacesContext context)
- See Also:
Faces.getResponse()
-
getResponseBufferSize
public static int getResponseBufferSize(FacesContext context)
- See Also:
Faces.getResponseBufferSize()
-
getResponseCharacterEncoding
public static String getResponseCharacterEncoding(FacesContext context)
- See Also:
Faces.getResponseCharacterEncoding()
-
setResponseStatus
public static void setResponseStatus(FacesContext context, int status)
- See Also:
Faces.setResponseStatus(int)
-
redirect
public static void redirect(FacesContext context, String url, Object... paramValues)
- See Also:
Faces.redirect(String, Object...)
-
redirectPermanent
public static void redirectPermanent(FacesContext context, String url, Object... paramValues)
-
refresh
public static void refresh(FacesContext context)
- See Also:
Faces.refresh()
-
refreshWithQueryString
public static void refreshWithQueryString(FacesContext context)
- See Also:
Faces.refreshWithQueryString()
-
responseSendError
public static void responseSendError(FacesContext context, int status, String message)
- See Also:
Faces.responseSendError(int, String)
-
addResponseHeader
public static void addResponseHeader(FacesContext context, String name, String value)
- See Also:
Faces.addResponseHeader(String, String)
-
isResponseCommitted
public static boolean isResponseCommitted(FacesContext context)
- See Also:
Faces.isResponseCommitted()
-
responseReset
public static void responseReset(FacesContext context)
- See Also:
Faces.responseReset()
-
isRenderResponse
public static boolean isRenderResponse(FacesContext context)
- See Also:
Faces.isRenderResponse()
-
login
public static void login(FacesContext context, String username, String password) throws ServletException
- Throws:
ServletException
- See Also:
Faces.login(String, String)
-
authenticate
public static boolean authenticate(FacesContext context) throws ServletException
- Throws:
ServletException
- See Also:
Faces.authenticate()
-
logout
public static void logout(FacesContext context) throws ServletException
- Throws:
ServletException
- See Also:
Faces.logout()
-
getRemoteUser
public static String getRemoteUser(FacesContext context)
- See Also:
Faces.getRemoteUser()
-
isUserInRole
public static boolean isUserInRole(FacesContext context, String role)
- See Also:
Faces.isUserInRole(String)
-
getRequestCookie
public static String getRequestCookie(FacesContext context, String name)
- See Also:
Faces.getRequestCookie(String)
-
addResponseCookie
public static void addResponseCookie(FacesContext context, String name, String value, int maxAge)
-
addResponseCookie
public static void addResponseCookie(FacesContext context, String name, String value, String path, int maxAge)
-
addResponseCookie
public static void addResponseCookie(FacesContext context, String name, String value, String domain, String path, int maxAge)
-
addResponseCookie
public static void addResponseCookie(FacesContext context, String name, String value, String domain, String path, int maxAge, boolean httpOnly)
-
addResponseCookie
public static void addResponseCookie(FacesContext context, String name, String value, String domain, String path, int maxAge, boolean httpOnly, Map<String,String> attributes)
-
removeResponseCookie
public static void removeResponseCookie(FacesContext context, String name, String path)
-
getSession
public static HttpSession getSession(FacesContext context)
- See Also:
Faces.getSession()
-
getSession
public static HttpSession getSession(FacesContext context, boolean create)
- See Also:
Faces.getSession(boolean)
-
getSessionId
public static String getSessionId(FacesContext context)
- See Also:
Faces.getSessionId()
-
invalidateSession
public static void invalidateSession(FacesContext context)
- See Also:
Faces.invalidateSession()
-
hasSession
public static boolean hasSession(FacesContext context)
- See Also:
Faces.hasSession()
-
isSessionNew
public static boolean isSessionNew(FacesContext context)
- See Also:
Faces.isSessionNew()
-
isRequestedSessionExpired
public static boolean isRequestedSessionExpired(FacesContext context)
- See Also:
Faces.isRequestedSessionExpired()
-
getSessionCreationTime
public static long getSessionCreationTime(FacesContext context)
- See Also:
Faces.getSessionCreationTime()
-
getSessionLastAccessedTime
public static long getSessionLastAccessedTime(FacesContext context)
- See Also:
Faces.getSessionLastAccessedTime()
-
getSessionMaxInactiveInterval
public static int getSessionMaxInactiveInterval(FacesContext context)
- See Also:
Faces.getSessionMaxInactiveInterval()
-
setSessionMaxInactiveInterval
public static void setSessionMaxInactiveInterval(FacesContext context, int seconds)
- See Also:
Faces.setSessionMaxInactiveInterval(int)
-
hasSessionTimedOut
public static boolean hasSessionTimedOut(FacesContext context)
- See Also:
Faces.hasSessionTimedOut()
-
getServletContext
public static ServletContext getServletContext(FacesContext context)
- See Also:
Faces.getServletContext()
-
getInitParameterMap
public static Map<String,String> getInitParameterMap(FacesContext context)
- See Also:
Faces.getInitParameterMap()
-
getInitParameter
public static String getInitParameter(FacesContext context, String name)
- See Also:
Faces.getInitParameter(String)
-
getInitParameterOrDefault
public static String getInitParameterOrDefault(FacesContext context, String name, String defaultValue)
-
getMimeType
public static String getMimeType(FacesContext context, String name)
- See Also:
Faces.getMimeType(String)
-
getResource
public static URL getResource(FacesContext context, String path) throws MalformedURLException
- Throws:
MalformedURLException
- See Also:
Faces.getResource(String)
-
getResourceAsStream
public static InputStream getResourceAsStream(FacesContext context, String path)
- See Also:
Faces.getResourceAsStream(String)
-
getResourcePaths
public static Set<String> getResourcePaths(FacesContext context, String path)
- See Also:
Faces.getResourcePaths(String)
-
getRealPath
public static String getRealPath(FacesContext context, String webContentPath)
- See Also:
Faces.getRealPath(String)
-
getRequestMap
public static Map<String,Object> getRequestMap(FacesContext context)
- See Also:
Faces.getRequestMap()
-
getRequestAttribute
public static <T> T getRequestAttribute(FacesContext context, String name)
- See Also:
Faces.getRequestAttribute(String)
-
getRequestAttribute
public static <T> T getRequestAttribute(FacesContext context, String name, Supplier<T> computeIfAbsent)
-
setRequestAttribute
public static void setRequestAttribute(FacesContext context, String name, Object value)
-
removeRequestAttribute
public static <T> T removeRequestAttribute(FacesContext context, String name)
- See Also:
Faces.removeRequestAttribute(String)
-
getFlash
public static Flash getFlash(FacesContext context)
- See Also:
Faces.getFlash()
-
getFlashAttribute
public static <T> T getFlashAttribute(FacesContext context, String name)
- See Also:
Faces.getFlashAttribute(String)
-
getFlashAttribute
public static <T> T getFlashAttribute(FacesContext context, String name, Supplier<T> computeIfAbsent)
-
setFlashAttribute
public static void setFlashAttribute(FacesContext context, String name, Object value)
- See Also:
Faces.setFlashAttribute(String, Object)
-
removeFlashAttribute
public static <T> T removeFlashAttribute(FacesContext context, String name)
- See Also:
Faces.removeFlashAttribute(String)
-
getViewMap
public static Map<String,Object> getViewMap(FacesContext context)
- See Also:
Faces.getViewMap()
-
getViewAttribute
public static <T> T getViewAttribute(FacesContext context, String name)
- See Also:
Faces.getViewAttribute(String)
-
getViewAttribute
public static <T> T getViewAttribute(FacesContext context, String name, Supplier<T> computeIfAbsent)
- See Also:
Faces.getViewAttribute(String, Supplier)
-
setViewAttribute
public static void setViewAttribute(FacesContext context, String name, Object value)
- See Also:
Faces.setViewAttribute(String, Object)
-
removeViewAttribute
public static <T> T removeViewAttribute(FacesContext context, String name)
- See Also:
Faces.removeViewAttribute(String)
-
getSessionMap
public static Map<String,Object> getSessionMap(FacesContext context)
- See Also:
Faces.getSessionMap()
-
getSessionAttribute
public static <T> T getSessionAttribute(FacesContext context, String name)
- See Also:
Faces.getSessionAttribute(String)
-
getSessionAttribute
public static <T> T getSessionAttribute(FacesContext context, String name, Supplier<T> computeIfAbsent)
-
setSessionAttribute
public static void setSessionAttribute(FacesContext context, String name, Object value)
-
removeSessionAttribute
public static <T> T removeSessionAttribute(FacesContext context, String name)
- See Also:
Faces.removeSessionAttribute(String)
-
getApplicationMap
public static Map<String,Object> getApplicationMap(FacesContext context)
- See Also:
Faces.getApplicationMap()
-
getApplicationAttribute
public static <T> T getApplicationAttribute(FacesContext context, String name)
- See Also:
Faces.getApplicationAttribute(String)
-
getApplicationAttribute
public static <T> T getApplicationAttribute(FacesContext context, String name, Supplier<T> computeIfAbsent)
-
setApplicationAttribute
public static void setApplicationAttribute(FacesContext context, String name, Object value)
-
removeApplicationAttribute
public static <T> T removeApplicationAttribute(FacesContext context, String name)
- See Also:
Faces.removeApplicationAttribute(String)
-
sendFile
public static void sendFile(FacesContext context, File file, boolean attachment) throws IOException
- Throws:
IOException
- See Also:
Faces.sendFile(File, boolean)
-
sendFile
public static void sendFile(FacesContext context, File file, String filename, boolean attachment) throws IOException
- Throws:
IOException
- See Also:
Faces.sendFile(File, String, boolean)
-
sendFile
public static void sendFile(FacesContext context, Path path, boolean attachment) throws IOException
- Throws:
IOException
- See Also:
Faces.sendFile(Path, boolean)
-
sendFile
public static void sendFile(FacesContext context, Path path, String filename, boolean attachment) throws IOException
- Throws:
IOException
- See Also:
Faces.sendFile(Path, String, boolean)
-
sendFile
public static void sendFile(FacesContext context, byte[] content, String filename, boolean attachment)
- See Also:
Faces.sendFile(byte[], String, boolean)
-
sendFile
public static void sendFile(FacesContext context, InputStream content, String filename, boolean attachment)
-
sendFile
public static void sendFile(FacesContext context, String filename, boolean attachment, Callback.Output outputCallback)
-
-