public final class FacesLocal extends Object
Collection of utility methods for the JSF 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 of FacesLocal
obtains the FacesContext
from
the current thread by FacesContext.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. Invoking
FacesContext.getCurrentInstance()
is at its own an extremely cheap operation, however as it's to be obtained
as a ThreadLocal
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 as
FacesContext.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();
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");
Servlets
public static String getServerInfo(FacesContext context)
Faces.getServerInfo()
public static ProjectStage getProjectStage(FacesContext context)
Faces.getProjectStage()
public static boolean isDevelopment(FacesContext context)
Faces.isDevelopment()
public static boolean isSystemTest(FacesContext context)
Faces.isSystemTest()
public static boolean isProduction(FacesContext context)
Faces.isProduction()
public static String getMapping(FacesContext context)
Faces.getMapping()
public static boolean isPrefixMapping(FacesContext context)
Faces.isPrefixMapping()
public static <T> T evaluateExpressionGet(FacesContext context, String expression)
Faces.evaluateExpressionGet(String)
public static void evaluateExpressionSet(FacesContext context, String expression, Object value)
public static <T> T resolveExpressionGet(FacesContext context, Object base, String property)
public static void resolveExpressionSet(FacesContext context, Object base, String property, Object value)
public static <T> T getContextAttribute(FacesContext context, String name)
Faces.getContextAttribute(String)
public static void setContextAttribute(FacesContext context, String name, Object value)
public static Converter createConverter(FacesContext context, Object identifier)
Faces.createConverter(Object)
public static Converter createConverter(FacesContext context, String identifier)
Faces.createConverter(String)
public static Converter createConverter(FacesContext context, Class<?> identifier)
Faces.createConverter(Class)
public static Validator createValidator(FacesContext context, Object identifier)
Faces.createValidator(Object)
public static Validator createValidator(FacesContext context, String identifier)
Faces.createValidator(String)
public static Validator createValidator(FacesContext context, Class<?> identifier)
Faces.createValidator(Class)
public static Lifecycle getLifecycle(FacesContext context)
Faces.getLifecycle()
public static void setViewRoot(FacesContext context, String viewId)
Faces.setViewRoot(String)
public static String getViewId(FacesContext context)
Faces.getViewId()
public static String getViewIdWithParameters(FacesContext context)
Faces.getViewIdWithParameters()
public static String getViewName(FacesContext context)
Faces.getViewName()
public static ViewDeclarationLanguage getViewDeclarationLanguage(FacesContext context)
Faces.getViewDeclarationLanguage()
public static RenderKit getRenderKit(FacesContext context)
Faces.getRenderKit()
public static String normalizeViewId(FacesContext context, String path)
Faces.normalizeViewId(String)
public static Collection<UIViewParameter> getViewParameters(FacesContext context)
Faces.getViewParameters()
public static Map<String,List<String>> getViewParameterMap(FacesContext context)
Faces.getViewParameterMap()
public static Map<String,Object> getMetadataAttributes(FacesContext context, String viewId)
Faces.getMetadataAttributes(String)
public static Map<String,Object> getMetadataAttributes(FacesContext context)
Faces.getMetadataAttributes()
public static <T> T getMetadataAttribute(FacesContext context, String viewId, String name)
public static <T> T getMetadataAttribute(FacesContext context, String name)
Faces.getMetadataAttribute(String)
public static Locale getLocale(FacesContext context)
Faces.getLocale()
public static Locale getDefaultLocale(FacesContext context)
Faces.getDefaultLocale()
public static List<Locale> getSupportedLocales(FacesContext context)
Faces.getSupportedLocales()
public static void setLocale(FacesContext context, Locale locale)
Faces.setLocale(Locale)
public static ResourceBundle getMessageBundle(FacesContext context)
Faces.getMessageBundle()
public static ResourceBundle getResourceBundle(FacesContext context, String var)
Faces.getResourceBundle(String)
public static Map<String,ResourceBundle> getResourceBundles(FacesContext context)
Faces.getResourceBundles()
public static String getBundleString(FacesContext context, String key)
Faces.getBundleString(String)
public static void navigate(FacesContext context, String outcome)
Faces.navigate(String)
public static String getBookmarkableURL(FacesContext context, Map<String,List<String>> params, boolean includeViewParams)
Faces.getBookmarkableURL(Map, boolean)
public static String getBookmarkableURL(FacesContext context, String viewId, Map<String,List<String>> params, boolean includeViewParams)
public static String getBookmarkableURL(FacesContext context, Collection<? extends ParamHolder> params, boolean includeViewParams)
public static String getBookmarkableURL(FacesContext context, String viewId, Collection<? extends ParamHolder> params, boolean includeViewParams)
public static FaceletContext getFaceletContext(FacesContext context)
Faces.getFaceletContext()
public static <T> T getFaceletAttribute(FacesContext context, String name)
Faces.getFaceletAttribute(String)
public static void setFaceletAttribute(FacesContext context, String name, Object value)
public static HttpServletRequest getRequest(FacesContext context)
Faces.getRequest()
public static boolean isAjaxRequest(FacesContext context)
Faces.isAjaxRequest()
public static boolean isAjaxRequestWithPartialRendering(FacesContext context)
public static boolean isPostback(FacesContext context)
Faces.isPostback()
public static Map<String,String> getRequestParameterMap(FacesContext context)
Faces.getRequestParameterMap()
public static String getRequestParameter(FacesContext context, String name)
Faces.getRequestParameter(String)
public static <T> T getRequestParameter(FacesContext context, String name, Class<T> type)
Faces.getRequestParameter(String, Class)
public static Map<String,String[]> getRequestParameterValuesMap(FacesContext context)
Faces.getRequestParameterValuesMap()
public static String[] getRequestParameterValues(FacesContext context, String name)
Faces.getRequestParameterValues(String)
public static <T> T[] getRequestParameterValues(FacesContext context, String name, Class<T> type)
public static Collection<Part> getRequestParts(FacesContext context)
Faces.getRequestParts()
public static Part getRequestPart(FacesContext context, String name)
Faces.getRequestPart(String)
public static Collection<Part> getRequestParts(FacesContext context, String name)
Faces.getRequestParts(String)
public static Map<String,String> getRequestHeaderMap(FacesContext context)
Faces.getRequestHeaderMap()
public static String getRequestHeader(FacesContext context, String name)
Faces.getRequestHeader(String)
public static Map<String,String[]> getRequestHeaderValuesMap(FacesContext context)
Faces.getRequestHeaderValuesMap()
public static String[] getRequestHeaderValues(FacesContext context, String name)
Faces.getRequestHeaderValues(String)
public static String getRequestContextPath(FacesContext context)
Faces.getRequestContextPath()
public static String getRequestServletPath(FacesContext context)
Faces.getRequestServletPath()
public static String getRequestPathInfo(FacesContext context)
Faces.getRequestPathInfo()
public static String getRequestHostname(FacesContext context)
Faces.getRequestHostname()
public static String getRequestBaseURL(FacesContext context)
Faces.getRequestBaseURL()
public static String getRequestDomainURL(FacesContext context)
Faces.getRequestDomainURL()
public static String getRequestURL(FacesContext context)
Faces.getRequestURL()
public static String getRequestURI(FacesContext context)
Faces.getRequestURI()
public static String getRequestQueryString(FacesContext context)
Faces.getRequestQueryString()
public static Map<String,List<String>> getRequestQueryStringMap(FacesContext context)
Faces.getRequestQueryStringMap()
public static String getRequestURLWithQueryString(FacesContext context)
Faces.getRequestURLWithQueryString()
public static String getRequestURIWithQueryString(FacesContext context)
Faces.getRequestURIWithQueryString()
@Deprecated public static String getForwardRequestURI(FacesContext context)
getRequestURI(FacesContext)
. Use it instead.
JSF has as to retrieving request URI no business of knowing if the request is forwarded/rewritten or not.Faces.getForwardRequestURI()
@Deprecated public static String getForwardRequestQueryString(FacesContext context)
getRequestQueryString(FacesContext)
. Use it instead.
JSF has as to retrieving request URI no business of knowing if the request is forwarded/rewritten or not.Faces.getForwardRequestQueryString()
@Deprecated public static String getForwardRequestURIWithQueryString(FacesContext context)
getRequestURIWithQueryString(FacesContext)
. Use it instead.
JSF has as to retrieving request URI no business of knowing if the request is forwarded/rewritten or not.public static String getRemoteAddr(FacesContext context)
Faces.getRemoteAddr()
public static HttpServletResponse getResponse(FacesContext context)
Faces.getResponse()
public static int getResponseBufferSize(FacesContext context)
Faces.getResponseBufferSize()
public static String getResponseCharacterEncoding(FacesContext context)
Faces.getResponseCharacterEncoding()
public static void setResponseStatus(FacesContext context, int status)
Faces.setResponseStatus(int)
public static void redirect(FacesContext context, String url, String... paramValues) throws IOException
IOException
Faces.redirect(String, String...)
public static void redirectPermanent(FacesContext context, String url, String... paramValues)
public static void refresh(FacesContext context) throws IOException
IOException
Faces.refresh()
public static void refreshWithQueryString(FacesContext context) throws IOException
IOException
Faces.refreshWithQueryString()
public static void responseSendError(FacesContext context, int status, String message) throws IOException
IOException
Faces.responseSendError(int, String)
public static void addResponseHeader(FacesContext context, String name, String value)
Faces.addResponseHeader(String, String)
public static boolean isResponseCommitted(FacesContext context)
Faces.isResponseCommitted()
public static void responseReset(FacesContext context)
Faces.responseReset()
public static boolean isRenderResponse(FacesContext context)
Faces.isRenderResponse()
public static void login(FacesContext context, String username, String password) throws ServletException
ServletException
Faces.login(String, String)
public static boolean authenticate(FacesContext context) throws ServletException, IOException
ServletException
IOException
Faces.authenticate()
public static void logout(FacesContext context) throws ServletException
ServletException
Faces.logout()
public static String getRemoteUser(FacesContext context)
Faces.getRemoteUser()
public static boolean isUserInRole(FacesContext context, String role)
Faces.isUserInRole(String)
public static String getRequestCookie(FacesContext context, String name)
Faces.getRequestCookie(String)
public static void addResponseCookie(FacesContext context, String name, String value, int maxAge)
public static void addResponseCookie(FacesContext context, String name, String value, String path, int maxAge)
public static void addResponseCookie(FacesContext context, String name, String value, String domain, String path, int maxAge)
public static void removeResponseCookie(FacesContext context, String name, String path)
public static HttpSession getSession(FacesContext context)
Faces.getSession()
public static HttpSession getSession(FacesContext context, boolean create)
Faces.getSession(boolean)
public static String getSessionId(FacesContext context)
Faces.getSessionId()
public static void invalidateSession(FacesContext context)
Faces.invalidateSession()
public static boolean hasSession(FacesContext context)
Faces.hasSession()
public static boolean isSessionNew(FacesContext context)
Faces.isSessionNew()
public static long getSessionCreationTime(FacesContext context)
Faces.getSessionCreationTime()
public static long getSessionLastAccessedTime(FacesContext context)
Faces.getSessionLastAccessedTime()
public static int getSessionMaxInactiveInterval(FacesContext context)
Faces.getSessionMaxInactiveInterval()
public static void setSessionMaxInactiveInterval(FacesContext context, int seconds)
Faces.setSessionMaxInactiveInterval(int)
public static boolean hasSessionTimedOut(FacesContext context)
Faces.hasSessionTimedOut()
public static ServletContext getServletContext(FacesContext context)
Faces.getServletContext()
public static Map<String,String> getInitParameterMap(FacesContext context)
Faces.getInitParameterMap()
public static String getInitParameter(FacesContext context, String name)
Faces.getInitParameter(String)
public static String getMimeType(FacesContext context, String name)
Faces.getMimeType(String)
public static URL getResource(FacesContext context, String path) throws MalformedURLException
MalformedURLException
Faces.getResource(String)
public static InputStream getResourceAsStream(FacesContext context, String path)
Faces.getResourceAsStream(String)
public static Set<String> getResourcePaths(FacesContext context, String path)
Faces.getResourcePaths(String)
public static String getRealPath(FacesContext context, String webContentPath)
Faces.getRealPath(String)
public static Map<String,Object> getRequestMap(FacesContext context)
Faces.getRequestMap()
public static <T> T getRequestAttribute(FacesContext context, String name)
Faces.getRequestAttribute(String)
public static void setRequestAttribute(FacesContext context, String name, Object value)
public static <T> T removeRequestAttribute(FacesContext context, String name)
Faces.removeRequestAttribute(String)
public static Flash getFlash(FacesContext context)
Faces.getFlash()
public static <T> T getFlashAttribute(FacesContext context, String name)
Faces.getFlashAttribute(String)
public static void setFlashAttribute(FacesContext context, String name, Object value)
Faces.setFlashAttribute(String, Object)
public static <T> T removeFlashAttribute(FacesContext context, String name)
Faces.removeFlashAttribute(String)
public static Map<String,Object> getViewMap(FacesContext context)
Faces.getViewMap()
public static <T> T getViewAttribute(FacesContext context, String name)
Faces.getViewAttribute(String)
public static void setViewAttribute(FacesContext context, String name, Object value)
Faces.setViewAttribute(String, Object)
public static <T> T removeViewAttribute(FacesContext context, String name)
Faces.removeViewAttribute(String)
public static Map<String,Object> getSessionMap(FacesContext context)
Faces.getSessionMap()
public static <T> T getSessionAttribute(FacesContext context, String name)
Faces.getSessionAttribute(String)
public static void setSessionAttribute(FacesContext context, String name, Object value)
public static <T> T removeSessionAttribute(FacesContext context, String name)
Faces.removeSessionAttribute(String)
public static Map<String,Object> getApplicationMap(FacesContext context)
Faces.getApplicationMap()
public static <T> T getApplicationAttribute(FacesContext context, String name)
Faces.getApplicationAttribute(String)
public static void setApplicationAttribute(FacesContext context, String name, Object value)
public static <T> T removeApplicationAttribute(FacesContext context, String name)
Faces.removeApplicationAttribute(String)
public static void sendFile(FacesContext context, File file, boolean attachment) throws IOException
IOException
Faces.sendFile(File, boolean)
public static void sendFile(FacesContext context, byte[] content, String filename, boolean attachment) throws IOException
IOException
Faces.sendFile(byte[], String, boolean)
public static void sendFile(FacesContext context, InputStream content, String filename, boolean attachment) throws IOException
IOException
Faces.sendFile(InputStream, String, boolean)
public static void sendFile(FacesContext context, String filename, boolean attachment, Callback.Output outputCallback) throws IOException
Copyright © 2012–2018 OmniFaces. All rights reserved.