org.omnifaces.util
Class Faces

java.lang.Object
  extended by org.omnifaces.util.Faces

public final class Faces
extends java.lang.Object

Collection of utility methods for the JSF API that are mainly shortcuts for obtaining stuff from the thread local FacesContext. In effect, it 'flattens' the hierarchy of nested objects.

Do note that using the hierarchy is actually a better software design practice, but can lead to verbose code.

In addition, note that there's normally a minor overhead in obtaining the thread local FacesContext. In case client code needs to call methods in this class multiple times it's expected that performance will be slightly better if instead the FacesContext is obtained once and the required methods are called on that, although the difference is practically negligible when used in modern server hardware.

Author:
Arjan Tijms, Bauke Scholtz

Method Summary
static void addResponseCookie(java.lang.String name, java.lang.String value, java.lang.String path, int maxAge)
          Add a cookie with given name, value, path and maxage to the HTTP response.
static void addResponseHeader(java.lang.String name, java.lang.String value)
          Add a header with given name and value to the HTTP response.
static boolean authenticate()
          Trigger the default container managed authentication mechanism on the current request.
static
<T> T
evaluateExpressionGet(java.lang.String expression)
          Programmatically evaluate the given EL expression and return the evaluated value.
static void evaluateExpressionSet(java.lang.String expression, java.lang.Object value)
          Programmatically evaluate the given EL expression and set the given value.
static javax.faces.application.Application getApplication()
          Returns the application singleton.
static
<T> T
getApplicationAttribute(javax.faces.context.FacesContext context, java.lang.String name)
          Returns the application scope attribute value associated with the given name.
static
<T> T
getApplicationAttribute(javax.servlet.ServletContext context, java.lang.String name)
          Returns the application scope attribute value associated with the given name.
static
<T> T
getApplicationAttribute(java.lang.String name)
          Returns the application scope attribute value associated with the given name.
static javax.faces.application.Application getApplicationFromFactory()
          Gets the JSF Application singleton from the FactoryFinder.
static java.util.Map<java.lang.String,java.lang.Object> getApplicationMap()
          Returns the application scope map.
static javax.faces.context.FacesContext getContext()
          Returns the current faces context.
static javax.faces.context.FacesContext getContext(javax.el.ELContext elContext)
          Returns the faces context that's stored in an ELContext.
static
<T> T
getContextAttribute(java.lang.String name)
          Returns the Faces context attribute value associated with the given name.
static javax.faces.event.PhaseId getCurrentPhaseId()
          Returns the current phase ID.
static java.util.Locale getDefaultLocale()
          Returns the default locale, or null if there is none.
static javax.faces.context.ExternalContext getExternalContext()
          Returns the current external context.
static
<T> T
getFaceletAttribute(java.lang.String name)
          Returns the Facelet attribute value associated with the given name.
static javax.faces.view.facelets.FaceletContext getFaceletContext()
          Returns the Facelet context.
static javax.servlet.ServletRegistration getFacesServletRegistration(javax.servlet.ServletContext servletContext)
          Gets the ServletRegistration associated with the FacesServlet.
static javax.faces.context.Flash getFlash()
          Returns the flash scope.
static
<T> T
getFlashAttribute(java.lang.String name)
          Returns the flash scope attribute value associated with the given name.
static java.lang.String getImplInfo()
          Returns the implementation information of currently loaded JSF implementation.
static java.lang.String getInitParameter(java.lang.String name)
          Returns the application initialization parameter.
static java.util.Map<java.lang.String,java.lang.String> getInitParameterMap()
          Returns the application initialization parameter map.
static java.util.Locale getLocale()
          Returns the current locale.
static java.lang.String getMapping()
          Determines and returns the faces servlet mapping used in the current request.
static
<T> T
getMetadataAttribute(java.lang.String name)
          Returns the metadata attribute of the current view associated with the given name.
static
<T> T
getMetadataAttribute(java.lang.String viewId, java.lang.String name)
          Returns the metadata attribute of the given view ID associated with the given name.
static java.util.Map<java.lang.String,java.lang.Object> getMetadataAttributes(java.lang.String viewId)
          Returns the metadata attribute map of the given view ID, or an empty map if there is no view metadata.
static java.lang.String getMimeType(java.lang.String name)
          Returns the mime type for the given file name.
static java.lang.String getRealPath(java.lang.String webContentPath)
          Returns the absolute disk file system path representation of the given web content path.
static java.lang.String getRemoteAddr()
          Returns the Internet Protocol (IP) address of the client that sent the request.
static java.lang.String getRemoteUser()
          Returns the name of the logged-in user for container managed FORM based authentication, if any.
static javax.servlet.http.HttpServletRequest getRequest()
          Returns the HTTP servlet request.
static
<T> T
getRequestAttribute(javax.faces.context.FacesContext context, java.lang.String name)
          Returns the request scope attribute value associated with the given name.
static
<T> T
getRequestAttribute(java.lang.String name)
          Returns the request scope attribute value associated with the given name.
static java.lang.String getRequestBaseURL()
          Returns the HTTP request base URL.
static java.lang.String getRequestBaseURL(javax.servlet.http.HttpServletRequest request)
          Returns the HTTP request base URL.
static java.lang.String getRequestContextPath()
          Returns the HTTP request context path.
static java.lang.String getRequestCookie(java.lang.String name)
          Returns the value of the HTTP request cookie associated with the given name.
static java.lang.String getRequestDomainURL()
          Returns the HTTP request domain URL.
static java.lang.String getRequestHeader(java.lang.String name)
          Returns the HTTP request header value associated with the given name.
static java.util.Map<java.lang.String,java.lang.String> getRequestHeaderMap()
          Returns the HTTP request header map.
static java.lang.String[] getRequestHeaderValues(java.lang.String name)
          Returns the HTTP request header values associated with the given name.
static java.util.Map<java.lang.String,java.lang.String[]> getRequestHeaderValuesMap()
          Returns the HTTP request header values map.
static java.util.Map<java.lang.String,java.lang.Object> getRequestMap()
          Returns the request scope map.
static java.lang.String getRequestParameter(java.lang.String name)
          Returns the HTTP request parameter value associated with the given name.
static java.util.Map<java.lang.String,java.lang.String> getRequestParameterMap()
          Returns the HTTP request parameter map.
static java.lang.String[] getRequestParameterValues(java.lang.String name)
          Returns the HTTP request parameter values associated with the given name.
static java.util.Map<java.lang.String,java.lang.String[]> getRequestParameterValuesMap()
          Returns the HTTP request parameter values map.
static java.lang.String getRequestPathInfo()
          Returns the HTTP request path info.
static java.lang.String getRequestQueryString()
          Returns the HTTP request query string.
static java.lang.String getRequestServletPath()
          Returns the HTTP request servlet path.
static java.lang.String getRequestURI()
          Returns the HTTP request URI.
static java.lang.String getRequestURL()
          Returns the HTTP request URL.
static java.net.URL getResource(java.lang.String path)
          Returns a URL for an application resource mapped to the specified path, if it exists; otherwise, return null.
static java.io.InputStream getResourceAsStream(java.lang.String path)
          Returns an input stream for an application resource mapped to the specified path, if it exists; otherwise, return null.
static java.util.Set<java.lang.String> getResourcePaths(java.lang.String path)
          Returns a set of available application resource paths matching the specified path.
static javax.servlet.http.HttpServletResponse getResponse()
          Returns the HTTP servlet response.
static int getResponseBufferSize()
          Returns the HTTP response buffer size.
static java.lang.String getResponseCharacterEncoding()
          Returns the HTTP response character encoding.
static java.lang.String getServerInfo()
          Returns the server information of currently running application server implementation.
static javax.servlet.ServletContext getServletContext()
          Returns the servlet context.
static javax.servlet.http.HttpSession getSession()
          Returns the HTTP session and creates one if one doesn't exist.
static javax.servlet.http.HttpSession getSession(boolean create)
          Returns the HTTP session and creates one if one doesn't exist and create argument is true, otherwise don't create one and return null.
static
<T> T
getSessionAttribute(java.lang.String name)
          Returns the session scope attribute value associated with the given name.
static long getSessionCreationTime()
          Returns the time when the HTTP session was created, measured in epoch time.
static java.lang.String getSessionId()
          Returns a string containing the unique identifier assigned to this session.
static long getSessionLastAccessedTime()
          Returns the time of the previous request associated with the current HTTP session, measured in epoch time.
static java.util.Map<java.lang.String,java.lang.Object> getSessionMap()
          Returns the session scope map.
static int getSessionMaxInactiveInterval()
          Returns the HTTP session timeout in seconds.
static java.util.List<java.util.Locale> getSupportedLocales()
          Returns a list of all supported locales on this application, with the default locale as the first item, if any.
static
<T> T
getViewAttribute(java.lang.String name)
          Returns the view scope attribute value associated with the given name.
static java.lang.String getViewId()
          Returns the ID of the current view root, or null if there is no view.
static java.util.Map<java.lang.String,java.lang.Object> getViewMap()
          Returns the view scope map.
static java.util.Collection<javax.faces.component.UIViewParameter> getViewParameters()
          Returns the view parameters of the current view, or an empty collection if there is no view.
static javax.faces.component.UIViewRoot getViewRoot()
          Returns the current view root.
static boolean hasSession()
          Returns whether the HTTP session has already been created.
static boolean hasSessionTimedOut()
          Returns whether the HTTP session has been timed out for the current request.
static void includeFacelet(javax.faces.component.UIComponent component, java.lang.String path)
          Include the Facelet file at the given (relative) path as child of the given UI component.
static void invalidateSession()
          Invalidates the current HTTP session.
static boolean isAjaxRequest()
          Returns whether the current request is an ajax request.
static boolean isDevelopment()
          Returns whether we're in development stage.
static boolean isPostback()
          Returns whether the current request is a postback.
static boolean isPrefixMapping()
          Returns whether the faces servlet mapping used in the current request is a prefix mapping.
static boolean isPrefixMapping(java.lang.String mapping)
          Returns whether the given faces servlet mapping is a prefix mapping.
static boolean isRenderResponse()
          Returns true if we're currently in the render response phase.
static boolean isResponseCommitted()
          Returns whether the response is already committed.
static boolean isResponseComplete()
          Returns true if the FacesContext.responseComplete() has been called.
static boolean isSessionNew()
          Returns whether the HTTP session has been created for the first time in the current request.
static boolean isUserInRole(java.lang.String role)
          Returns whether the currently logged-in user has the given role.
static boolean isValidationFailed()
          Returns whether the validations phase of the current request has failed.
static void login(java.lang.String username, java.lang.String password)
          Perform programmatic login for container managed FORM based authentication.
static void logout()
          Perform programmatic logout for container managed FORM based authentication.
static void navigate(java.lang.String outcome)
          Perform the JSF navigation to the given outcome.
static java.lang.String normalizeViewId(java.lang.String path)
          Normalize the given path as a valid view ID based on the current mapping, if necessary.
static void redirect(java.lang.String url, java.lang.String... paramValues)
          Sends a temporary (302) redirect to the given URL.
static void redirectPermanent(java.lang.String url, java.lang.String... paramValues)
          Sends a permanent (301) redirect to the given URL.
static
<T> T
removeApplicationAttribute(java.lang.String name)
          Removes the application scope attribute value associated with the given name.
static
<T> T
removeFlashAttribute(java.lang.String name)
          Removes the flash scope attribute value associated with the given name.
static
<T> T
removeRequestAttribute(java.lang.String name)
          Removes the request scope attribute value associated with the given name.
static void removeResponseCookie(java.lang.String name, java.lang.String path)
          Remove the cookie with given name and path from the HTTP response.
static
<T> T
removeSessionAttribute(java.lang.String name)
          Removes the session scope attribute value associated with the given name.
static
<T> T
removeViewAttribute(java.lang.String name)
          Removes the view scope attribute value associated with the given name.
static void renderResponse()
          Signals JSF that, as soon as the current phase of the lifecycle has been completed, control should be passed to the Render Response phase, bypassing any phases that have not been executed yet.
static void responseComplete()
          Signals JSF that the response for this request has already been generated (such as providing a file download), and that the lifecycle should be terminated as soon as the current phase is completed.
static void responseReset()
          Resets the current response.
static void responseSendError(int status, java.lang.String message)
          Sends a HTTP response error with the given status and message.
static void sendFile(byte[] content, java.lang.String filename, boolean attachment)
          Send the given byte array as a file to the response.
static void sendFile(java.io.File file, boolean attachment)
          Send the given file to the response.
static void sendFile(java.io.InputStream content, java.lang.String filename, boolean attachment)
          Send the given input stream as a file to the response.
static void setApplicationAttribute(java.lang.String name, java.lang.Object value)
          Sets the application scope attribute value associated with the given name.
static void setContext(javax.faces.context.FacesContext context)
          Sets the given faces context as current instance.
static void setContextAttribute(java.lang.String name, java.lang.Object value)
          Sets the Faces context attribute value associated with the given name.
static void setFaceletAttribute(java.lang.String name, java.lang.Object value)
          Sets the Facelet attribute value associated with the given name.
static void setFlashAttribute(java.lang.String name, java.lang.Object value)
          Sets the flash scope attribute value associated with the given name.
static void setLocale(java.util.Locale locale)
          Set the locale of the current view, which is to be used in localizing of the response.
static void setRequestAttribute(java.lang.String name, java.lang.Object value)
          Sets the request scope attribute value associated with the given name.
static void setSessionAttribute(java.lang.String name, java.lang.Object value)
          Sets the session scope attribute value associated with the given name.
static void setSessionMaxInactiveInterval(int seconds)
          Sets the HTTP session timeout in seconds.
static void setViewAttribute(java.lang.String name, java.lang.Object value)
          Sets the view scope attribute value associated with the given name.
static void setViewRoot(java.lang.String viewId)
          Sets the current view root to the given view ID.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getContext

public static javax.faces.context.FacesContext getContext()
Returns the current faces context.

Note that whenever you absolutely need this method to perform a general task, you might want to consider to submit a feature request to OmniFaces in order to add a new utility method which performs exactly this general task.

Returns:
The current faces context.
See Also:
FacesContext.getCurrentInstance()

getContext

public static javax.faces.context.FacesContext getContext(javax.el.ELContext elContext)
Returns the faces context that's stored in an ELContext.

Note that this only works for an ELContext that is created in the context of JSF.

Parameters:
elContext - the EL context to obtain the faces context from.
Returns:
the faces context that's stored in the given ELContext.
Since:
1.2

setContext

public static void setContext(javax.faces.context.FacesContext context)
Sets the given faces context as current instance. Use this if you have a custom FacesContextWrapper which you'd like to (temporarily) use as the current instance of the faces context.

Parameters:
context - The faces context to be set as the current instance.
Since:
1.3

getExternalContext

public static javax.faces.context.ExternalContext getExternalContext()
Returns the current external context.

Note that whenever you absolutely need this method to perform a general task, you might want to consider to submit a feature request to OmniFaces in order to add a new utility method which performs exactly this general task.

Returns:
The current external context.
See Also:
FacesContext.getExternalContext()

getApplication

public static javax.faces.application.Application getApplication()
Returns the application singleton.

Note that whenever you absolutely need this method to perform a general task, you might want to consider to submit a feature request to OmniFaces in order to add a new utility method which performs exactly this general task.

Returns:
The faces application singleton.
See Also:
FacesContext.getApplication()

getApplicationFromFactory

public static javax.faces.application.Application getApplicationFromFactory()
Gets the JSF Application singleton from the FactoryFinder.

This method is an alternative for getApplication() for those situations where the FacesContext isn't available.

Returns:
The faces application singleton.

getImplInfo

public static java.lang.String getImplInfo()
Returns the implementation information of currently loaded JSF implementation. E.g. "Mojarra 2.1.7-FCS".

Returns:
The implementation information of currently loaded JSF implementation.
See Also:
Package.getImplementationTitle(), Package.getImplementationVersion()

getServerInfo

public static java.lang.String getServerInfo()
Returns the server information of currently running application server implementation.

Returns:
The server information of currently running application server implementation.
See Also:
ServletContext.getServerInfo()

isDevelopment

public static boolean isDevelopment()
Returns whether we're in development stage. This will be the case when the javax.faces.PROJECT_STAGE context parameter in web.xml is set to Development.

Returns:
true if we're in development stage, otherwise false.
See Also:
Application.getProjectStage()

getMapping

public static java.lang.String getMapping()
Determines and returns the faces servlet mapping used in the current request. If JSF is prefix mapped (e.g. /faces/*), then this returns the whole path, with a leading slash (e.g. /faces). If JSF is suffix mapped (e.g. *.xhtml), then this returns the whole extension (e.g. .xhtml).

Returns:
The faces servlet mapping (without the wildcard).
See Also:
getRequestPathInfo(), getRequestServletPath()

isPrefixMapping

public static boolean isPrefixMapping()
Returns whether the faces servlet mapping used in the current request is a prefix mapping.

Returns:
true if the faces servlet mapping used in the current request is a prefix mapping, otherwise false.
See Also:
getMapping(), isPrefixMapping(String)

isPrefixMapping

public static boolean isPrefixMapping(java.lang.String mapping)
Returns whether the given faces servlet mapping is a prefix mapping. Use this method in preference to isPrefixMapping() when you already have obtained the mapping from getMapping() so that the mapping won't be calculated twice.

Parameters:
mapping - The mapping to be tested.
Returns:
true if the faces servlet mapping used in the current request is a prefix mapping, otherwise false.
Throws:
java.lang.NullPointerException - When mapping is null.

getCurrentPhaseId

public static javax.faces.event.PhaseId getCurrentPhaseId()
Returns the current phase ID.

Returns:
The current phase ID.
See Also:
FacesContext.getCurrentPhaseId()

evaluateExpressionGet

public static <T> T evaluateExpressionGet(java.lang.String expression)
Programmatically evaluate the given EL expression and return the evaluated value.

Type Parameters:
T - The expected return type.
Parameters:
expression - The EL expression to be evaluated.
Returns:
The evaluated value of the given EL expression.
Throws:
java.lang.ClassCastException - When T is of wrong type.
See Also:
Application.evaluateExpressionGet(FacesContext, String, Class)

evaluateExpressionSet

public static void evaluateExpressionSet(java.lang.String expression,
                                         java.lang.Object value)
Programmatically evaluate the given EL expression and set the given value.

Parameters:
expression - The EL expression to be evaluated.
value - The value to be set in the property behind the EL expression.
Since:
1.1
See Also:
Application.getExpressionFactory(), ExpressionFactory.createValueExpression(ELContext, String, Class), ValueExpression.setValue(ELContext, Object)

getContextAttribute

public static <T> T getContextAttribute(java.lang.String name)
Returns the Faces context attribute value associated with the given name.

Parameters:
name - The Faces context attribute name.
Returns:
The Faces context attribute value associated with the given name.
Throws:
java.lang.ClassCastException - When T is of wrong type.
Since:
1.3
See Also:
FacesContext.getAttributes()

setContextAttribute

public static void setContextAttribute(java.lang.String name,
                                       java.lang.Object value)
Sets the Faces context attribute value associated with the given name.

Parameters:
name - The Faces context attribute name.
value - The Faces context attribute value.
Since:
1.3
See Also:
FacesContext.getAttributes()

getViewRoot

public static javax.faces.component.UIViewRoot getViewRoot()
Returns the current view root.

Returns:
The current view root.
See Also:
FacesContext.getViewRoot()

setViewRoot

public static void setViewRoot(java.lang.String viewId)
Sets the current view root to the given view ID. The view ID must start with a leading slash. If an invalid view ID is given, then the response will simply result in a 404.

Parameters:
viewId - The ID of the view which needs to be set as the current view root.
Since:
1.1
See Also:
ViewHandler.createView(FacesContext, String), FacesContext.setViewRoot(UIViewRoot)

getViewId

public static java.lang.String getViewId()
Returns the ID of the current view root, or null if there is no view.

Returns:
The ID of the current view root, or null if there is no view.
See Also:
UIViewRoot.getViewId()

normalizeViewId

public static java.lang.String normalizeViewId(java.lang.String path)
Normalize the given path as a valid view ID based on the current mapping, if necessary.

Parameters:
path - The path to be normalized as a valid view ID based on the current mapping.
Returns:
The path as a valid view ID.
See Also:
getMapping(), isPrefixMapping(String)

getViewParameters

public static java.util.Collection<javax.faces.component.UIViewParameter> getViewParameters()
Returns the view parameters of the current view, or an empty collection if there is no view.

Returns:
The view parameters of the current view, or an empty collection if there is no view.
See Also:
ViewMetadata.getViewParameters(UIViewRoot)

getMetadataAttributes

public static java.util.Map<java.lang.String,java.lang.Object> getMetadataAttributes(java.lang.String viewId)
Returns the metadata attribute map of the given view ID, or an empty map if there is no view metadata.

Parameters:
viewId - The view ID to return the metadata attribute map for.
Returns:
The metadata attribute map of the given view ID, or an empty map if there is no view metadata.
Since:
1.4
See Also:
ViewDeclarationLanguage.getViewMetadata(FacesContext, String)

getMetadataAttribute

public static <T> T getMetadataAttribute(java.lang.String viewId,
                                         java.lang.String name)
Returns the metadata attribute of the given view ID associated with the given name. Note: this is not the same as the view scope, for that use getViewAttribute(String).

Parameters:
viewId - The view ID to return the metadata attribute for.
name - The metadata attribute name.
Returns:
The metadata attribute of the given view ID associated with the given name.
Throws:
java.lang.ClassCastException - When T is of wrong type.
Since:
1.4
See Also:
ViewDeclarationLanguage.getViewMetadata(FacesContext, String)

getMetadataAttribute

public static <T> T getMetadataAttribute(java.lang.String name)
Returns the metadata attribute of the current view associated with the given name. Note: this is not the same as the view scope, for that use getViewAttribute(String).

Parameters:
name - The metadata attribute name.
Returns:
The metadata attribute of the current view associated with the given name.
Throws:
java.lang.ClassCastException - When T is of wrong type.
Since:
1.4
See Also:
UIComponentBase.getAttributes()

getLocale

public static java.util.Locale getLocale()
Returns the current locale. If the locale set in the JSF view root is not null, then return it. Else if the client preferred locale is not null and is among supported locales, then return it. Else if the JSF default locale is not null, then return it. Else return the system default locale.

Returns:
The current locale.
See Also:
UIViewRoot.getLocale(), ExternalContext.getRequestLocale(), Application.getDefaultLocale(), Locale.getDefault()

getDefaultLocale

public static java.util.Locale getDefaultLocale()
Returns the default locale, or null if there is none.

Returns:
The default locale, or null if there is none.
See Also:
Application.getDefaultLocale()

getSupportedLocales

public static java.util.List<java.util.Locale> getSupportedLocales()
Returns a list of all supported locales on this application, with the default locale as the first item, if any. This will return an empty list if there are no locales definied in faces-config.xml.

Returns:
A list of all supported locales on this application, with the default locale as the first item, if any.
See Also:
Application.getDefaultLocale(), Application.getSupportedLocales()

setLocale

public static void setLocale(java.util.Locale locale)
Set the locale of the current view, which is to be used in localizing of the response.

Parameters:
locale - The locale of the current view.
Throws:
java.lang.IllegalStateException - When there is no view (i.e. when it is null). This can happen if the method is called at the wrong moment in the JSF lifecycle, e.g. before the view has been restored/created.
Since:
1.2
See Also:
UIViewRoot.setLocale(Locale)

navigate

public static void navigate(java.lang.String outcome)
Perform the JSF navigation to the given outcome.

Parameters:
outcome - The navigation outcome.
See Also:
Application.getNavigationHandler(), NavigationHandler.handleNavigation(FacesContext, String, String)

getFaceletContext

public static javax.faces.view.facelets.FaceletContext getFaceletContext()
Returns the Facelet context.

Note that whenever you absolutely need this method to perform a general task, you might want to consider to submit a feature request to OmniFaces in order to add a new utility method which performs exactly this general task.

Returns:
The Facelet context.
Since:
1.1
See Also:
FaceletContext

includeFacelet

public static void includeFacelet(javax.faces.component.UIComponent component,
                                  java.lang.String path)
                           throws java.io.IOException
Include the Facelet file at the given (relative) path as child of the given UI component. This has the same effect as using <ui:include>. The path is relative to the current view ID and absolute to the webcontent root.

Parameters:
component - The component to include the Facelet file in.
path - The (relative) path to the Facelet file.
Throws:
java.io.IOException - Whenever something fails at I/O level. The caller should preferably not catch it, but just redeclare it in the action method. The servletcontainer will handle it.
Since:
1.1
See Also:
FaceletContext.includeFacelet(UIComponent, String)

getFaceletAttribute

public static <T> T getFaceletAttribute(java.lang.String name)
Returns the Facelet attribute value associated with the given name. This basically returns the value of the <ui:param> which is been declared inside the Facelet file, or is been passed into the Facelet file by e.g. an <ui:include>.

Parameters:
name - The Facelet attribute name.
Returns:
The Facelet attribute value associated with the given name.
Throws:
java.lang.ClassCastException - When T is of wrong type.
Since:
1.1
See Also:
FaceletContext.getAttribute(String)

setFaceletAttribute

public static void setFaceletAttribute(java.lang.String name,
                                       java.lang.Object value)
Sets the Facelet attribute value associated with the given name. This basically does the same as an <ui:param> which is been declared inside the Facelet file, or is been passed into the Facelet file by e.g. an <ui:include>.

Parameters:
name - The Facelet attribute name.
value - The Facelet attribute value.
Since:
1.1
See Also:
FaceletContext.setAttribute(String, Object)

getRequest

public static javax.servlet.http.HttpServletRequest getRequest()
Returns the HTTP servlet request.

Note that whenever you absolutely need this method to perform a general task, you might want to consider to submit a feature request to OmniFaces in order to add a new utility method which performs exactly this general task.

Returns:
The HTTP servlet request.
See Also:
ExternalContext.getRequest()

isAjaxRequest

public static boolean isAjaxRequest()
Returns whether the current request is an ajax request.

Returns:
true for an ajax request, false for a non-ajax (synchronous) request.
See Also:
PartialViewContext.isAjaxRequest()

isPostback

public static boolean isPostback()
Returns whether the current request is a postback.

Returns:
true for a postback, false for a non-postback (GET) request.
See Also:
FacesContext.isPostback()

isValidationFailed

public static boolean isValidationFailed()
Returns whether the validations phase of the current request has failed.

Returns:
true if the validations phase of the current request has failed, otherwise false.
See Also:
FacesContext.isValidationFailed()

getRequestParameterMap

public static java.util.Map<java.lang.String,java.lang.String> getRequestParameterMap()
Returns the HTTP request parameter map.

Returns:
The HTTP request parameter map.
See Also:
ExternalContext.getRequestParameterMap()

getRequestParameter

public static java.lang.String getRequestParameter(java.lang.String name)
Returns the HTTP request parameter value associated with the given name.

Parameters:
name - The HTTP request parameter name.
Returns:
The HTTP request parameter value associated with the given name.
See Also:
ExternalContext.getRequestParameterMap()

getRequestParameterValuesMap

public static java.util.Map<java.lang.String,java.lang.String[]> getRequestParameterValuesMap()
Returns the HTTP request parameter values map.

Returns:
The HTTP request parameter values map.
See Also:
ExternalContext.getRequestParameterValuesMap()

getRequestParameterValues

public static java.lang.String[] getRequestParameterValues(java.lang.String name)
Returns the HTTP request parameter values associated with the given name.

Parameters:
name - The HTTP request parameter name.
Returns:
The HTTP request parameter values associated with the given name.
See Also:
ExternalContext.getRequestParameterValuesMap()

getRequestHeaderMap

public static java.util.Map<java.lang.String,java.lang.String> getRequestHeaderMap()
Returns the HTTP request header map.

Returns:
The HTTP request header map.
See Also:
ExternalContext.getRequestHeaderMap()

getRequestHeader

public static java.lang.String getRequestHeader(java.lang.String name)
Returns the HTTP request header value associated with the given name.

Parameters:
name - The HTTP request header name.
Returns:
The HTTP request header value associated with the given name.
See Also:
ExternalContext.getRequestHeaderMap()

getRequestHeaderValuesMap

public static java.util.Map<java.lang.String,java.lang.String[]> getRequestHeaderValuesMap()
Returns the HTTP request header values map.

Returns:
The HTTP request header values map.
See Also:
ExternalContext.getRequestHeaderValuesMap()

getRequestHeaderValues

public static java.lang.String[] getRequestHeaderValues(java.lang.String name)
Returns the HTTP request header values associated with the given name.

Parameters:
name - The HTTP request header name.
Returns:
The HTTP request header values associated with the given name.
See Also:
ExternalContext.getRequestHeaderValuesMap()

getRequestContextPath

public static java.lang.String getRequestContextPath()
Returns the HTTP request context path. It's the webapp context name, with a leading slash. If the webapp runs on context root, then it returns an empty string.

Returns:
The HTTP request context path.
See Also:
ExternalContext.getRequestContextPath()

getRequestServletPath

public static java.lang.String getRequestServletPath()
Returns the HTTP request servlet path. If JSF is prefix mapped (e.g. /faces/*), then this returns the whole prefix mapping (e.g. /faces). If JSF is suffix mapped (e.g. *.xhtml), then this returns the whole part after the context path, with a leading slash.

Returns:
The HTTP request servlet path.
See Also:
ExternalContext.getRequestServletPath()

getRequestPathInfo

public static java.lang.String getRequestPathInfo()
Returns the HTTP request path info. If JSF is prefix mapped (e.g. /faces/*), then this returns the whole part after the prefix mapping, with a leading slash. If JSF is suffix mapped (e.g. *.xhtml), then this returns null.

Returns:
The HTTP request path info.
See Also:
ExternalContext.getRequestPathInfo()

getRequestBaseURL

public static java.lang.String getRequestBaseURL()
Returns the HTTP request base URL. This is the URL from the scheme, domain until with context path, including the trailing slash. This is the value you could use in HTML <base> tag.

Returns:
The HTTP request base URL.
See Also:
HttpServletRequest.getRequestURL(), HttpServletRequest.getRequestURI(), HttpServletRequest.getContextPath()

getRequestBaseURL

public static java.lang.String getRequestBaseURL(javax.servlet.http.HttpServletRequest request)
Returns the HTTP request base URL. This is the URL from the scheme, domain until with context path, including the trailing slash. This is the value you could use in HTML <base> tag.

Parameters:
request - The request for which the base URL is computed.
Returns:
The HTTP request base URL.
See Also:
HttpServletRequest.getRequestURL(), HttpServletRequest.getRequestURI(), HttpServletRequest.getContextPath()

getRequestDomainURL

public static java.lang.String getRequestDomainURL()
Returns the HTTP request domain URL. This is the URL with the scheme and domain, without any trailing slash.

Returns:
The HTTP request domain URL.
Since:
1.1
See Also:
HttpServletRequest.getRequestURL(), HttpServletRequest.getRequestURI()

getRequestURL

public static java.lang.String getRequestURL()
Returns the HTTP request URL. This is the full request URL as the enduser sees in browser address bar. This does not include the request query string.

Returns:
The HTTP request URL.
Since:
1.1
See Also:
HttpServletRequest.getRequestURL()

getRequestURI

public static java.lang.String getRequestURI()
Returns the HTTP request URI. This is the part after the domain in the request URL, including the leading slash. This does not include the request query string.

Returns:
The HTTP request URI.
Since:
1.1
See Also:
HttpServletRequest.getRequestURI()

getRequestQueryString

public static java.lang.String getRequestQueryString()
Returns the HTTP request query string. This is the part after the ? in the request URL as the enduser sees in browser address bar.

Returns:
The HTTP request query string.
Since:
1.1
See Also:
HttpServletRequest.getQueryString()

getRemoteAddr

public static java.lang.String getRemoteAddr()
Returns the Internet Protocol (IP) address of the client that sent the request. This will first check the X-Forwarded-For request header and if it's present, then return its first IP address, else just return ServletRequest.getRemoteAddr() unmodified.

Returns:
The IP address of the client.
Since:
1.2
See Also:
ServletRequest.getRemoteAddr()

getResponse

public static javax.servlet.http.HttpServletResponse getResponse()
Returns the HTTP servlet response.

Note that whenever you absolutely need this method to perform a general task, you might want to consider to submit a feature request to OmniFaces in order to add a new utility method which performs exactly this general task.

Returns:
The HTTP servlet response.
See Also:
ExternalContext.getResponse()

getResponseBufferSize

public static int getResponseBufferSize()
Returns the HTTP response buffer size. If Facelets is used and the javax.faces.FACELETS_BUFFER_SIZE context parameter is been set, then it's the context parameter value which will be returned. Otherwise it returns the implementation independent default value, which is 1024 in Mojarra.

Returns:
The HTTP response buffer size.
Since:
1.2
See Also:
ExternalContext.getResponseBufferSize()

getResponseCharacterEncoding

public static java.lang.String getResponseCharacterEncoding()
Returns the HTTP response character encoding.

Returns:
The HTTP response character encoding.
Since:
1.2
See Also:
ExternalContext.getResponseCharacterEncoding()

redirect

public static void redirect(java.lang.String url,
                            java.lang.String... paramValues)
                     throws java.io.IOException
Sends a temporary (302) redirect to the given URL. If the given URL does not start with http://, https:// or /, then the request context path will be prepended, otherwise it will be the unmodified redirect URL. So, when redirecting to another page in the same web application, always specify the full path from the context root on (which in turn does not need to start with /).

You can use String.format(String, Object...) placeholder %s in the redirect URL to represent placeholders for any request parameter values which needs to be URL-encoded. Here's a concrete example:

 Faces.redirect("other.xhtml?foo=%s&bar=%s", foo, bar);
 

This method implicitly also calls Flash.setRedirect(boolean) with true so that any flash scoped attributes will survive the redirect.

Parameters:
url - The URL to redirect the current response to.
paramValues - The request parameter values which you'd like to put URL-encoded in the given URL.
Throws:
java.io.IOException - Whenever something fails at I/O level. The caller should preferably not catch it, but just redeclare it in the action method. The servletcontainer will handle it.
java.lang.NullPointerException - When url is null.
See Also:
ExternalContext.redirect(String)

redirectPermanent

public static void redirectPermanent(java.lang.String url,
                                     java.lang.String... paramValues)
                              throws java.io.IOException
Sends a permanent (301) redirect to the given URL. If the given URL does not start with http://, https:// or /, then the request context path will be prepended, otherwise it will be the unmodified redirect URL. So, when redirecting to another page in the same web application, always specify the full path from the context root on (which in turn does not need to start with /).

You can use String.format(String, Object...) placeholder %s in the redirect URL to represent placeholders for any request parameter values which needs to be URL-encoded. Here's a concrete example:

 Faces.redirectPermanent("other.xhtml?foo=%s&bar=%s", foo, bar);
 

This method implicitly also calls Flash.setRedirect(boolean) with true so that any flash scoped attributes will survive the redirect.

This method does by design not work on ajax requests. It is not possible to return a "permanent redirect" via JSF ajax XML response.

Parameters:
url - The URL to redirect the current response to.
paramValues - The request parameter values which you'd like to put URL-encoded in the given URL.
Throws:
java.io.IOException - Whenever something fails at I/O level. The caller should preferably not catch it, but just redeclare it in the action method. The servletcontainer will handle it.
java.lang.NullPointerException - When url is null.
See Also:
ExternalContext.setResponseStatus(int), ExternalContext.setResponseHeader(String, String)

responseSendError

public static void responseSendError(int status,
                                     java.lang.String message)
                              throws java.io.IOException
Sends a HTTP response error with the given status and message. This will end up in either a custom <error-page> whose <error-code> matches the given status, or in a servlet container specific default error page if there is none. The message will be available in the error page as a request attribute with name javax.servlet.error.message. The FacesContext.responseComplete() will implicitly be called after sending the error.

Parameters:
status - The HTTP response status which is supposed to be in the range 4nn-5nn. You can use the constant field values of HttpServletResponse for this.
message - The message which is supposed to be available in the error page.
Throws:
java.io.IOException - Whenever something fails at I/O level. The caller should preferably not catch it, but just redeclare it in the action method. The servletcontainer will handle it.
See Also:
ExternalContext.responseSendError(int, String)

addResponseHeader

public static void addResponseHeader(java.lang.String name,
                                     java.lang.String value)
Add a header with given name and value to the HTTP response.

Parameters:
name - The header name.
value - The header value.
See Also:
ExternalContext.addResponseHeader(String, String)

isResponseCommitted

public static boolean isResponseCommitted()
Returns whether the response is already committed. That is, when the response headers and a part of the response body has already been sent to the client. This is usually a point of no return and you can't change the response anymore.

Returns:
true if the response is already committed, otherwise false.
Since:
1.1
See Also:
ExternalContext.isResponseCommitted()

responseReset

public static void responseReset()
Resets the current response. This will clear any headers which are been set and any data which is written to the response buffer which isn't committed yet.

Throws:
java.lang.IllegalStateException - When the response is already committed.
Since:
1.1
See Also:
ExternalContext.responseReset()

renderResponse

public static void renderResponse()
Signals JSF that, as soon as the current phase of the lifecycle has been completed, control should be passed to the Render Response phase, bypassing any phases that have not been executed yet.

Since:
1.4
See Also:
FacesContext.renderResponse()

isRenderResponse

public static boolean isRenderResponse()
Returns true if we're currently in the render response phase. This explicitly checks the current phase ID instead of FacesContext.getRenderResponse() as the latter may unexpectedly return false during a GET request when <f:viewParam> is been used.

Returns:
true if we're currently in the render response phase.
Since:
1.4
See Also:
FacesContext.getCurrentPhaseId()

responseComplete

public static void responseComplete()
Signals JSF that the response for this request has already been generated (such as providing a file download), and that the lifecycle should be terminated as soon as the current phase is completed.

Since:
1.4
See Also:
FacesContext.responseComplete()

isResponseComplete

public static boolean isResponseComplete()
Returns true if the FacesContext.responseComplete() has been called.

Returns:
true if the FacesContext.responseComplete() has been called.
Since:
1.4
See Also:
FacesContext.responseComplete()

login

public static void login(java.lang.String username,
                         java.lang.String password)
                  throws javax.servlet.ServletException
Perform programmatic login for container managed FORM based authentication. Note that configuration is container specific and unrelated to JSF. Refer the documentation of the servletcontainer using the keyword "realm".

Parameters:
username - The login username.
password - The login password.
Throws:
javax.servlet.ServletException - When the login is invalid, or when container managed FORM based authentication is not enabled.
See Also:
HttpServletRequest.login(String, String)

authenticate

public static boolean authenticate()
                            throws javax.servlet.ServletException,
                                   java.io.IOException
Trigger the default container managed authentication mechanism on the current request. It expects the username and password being available as predefinied request parameters on the current request and/or a custom JASPIC implementation.

Returns:
true if the authentication was successful, otherwise false.
Throws:
javax.servlet.ServletException - When the authentication has failed. The caller is responsible for handling it.
java.io.IOException - Whenever something fails at I/O level. The caller should preferably not catch it, but just redeclare it in the action method. The servletcontainer will handle it.
Since:
1.4
See Also:
HttpServletRequest.authenticate(HttpServletResponse)

logout

public static void logout()
                   throws javax.servlet.ServletException
Perform programmatic logout for container managed FORM based authentication. Note that this basically removes the user principal from the session. It's however better practice to just invalidate the session altogether, which will implicitly also remove the user principal. Just invoke invalidateSession() instead. Note that the user principal is still present in the response of the current request, it's therefore recommend to send a redirect after logout() or invalidateSession(). You can use redirect(String, String...) for this.

Throws:
javax.servlet.ServletException - When the logout has failed.
See Also:
HttpServletRequest.logout()

getRemoteUser

public static java.lang.String getRemoteUser()
Returns the name of the logged-in user for container managed FORM based authentication, if any.

Returns:
The name of the logged-in user for container managed FORM based authentication, if any.
See Also:
ExternalContext.getRemoteUser()

isUserInRole

public static boolean isUserInRole(java.lang.String role)
Returns whether the currently logged-in user has the given role.

Parameters:
role - The role to be checked on the currently logged-in user.
Returns:
true if the currently logged-in user has the given role, otherwise false.
See Also:
ExternalContext.isUserInRole(String)

getRequestCookie

public static java.lang.String getRequestCookie(java.lang.String name)
Returns the value of the HTTP request cookie associated with the given name. The value is implicitly URL-decoded with a charset of UTF-8.

Parameters:
name - The HTTP request cookie name.
Returns:
The value of the HTTP request cookie associated with the given name.
Throws:
java.lang.UnsupportedOperationException - If UTF-8 is not supported on this machine.
See Also:
ExternalContext.getRequestCookieMap()

addResponseCookie

public static void addResponseCookie(java.lang.String name,
                                     java.lang.String value,
                                     java.lang.String path,
                                     int maxAge)
Add a cookie with given name, value, path and maxage to the HTTP response. The cookie value will implicitly be URL-encoded with UTF-8 so that any special characters can be stored in the cookie. The cookie will implicitly be set to secure when the current request is secure (i.e. when the current request is a HTTPS request).

Parameters:
name - The cookie name.
value - The cookie value.
path - The cookie path. If this is /, then the cookie is available in all pages of the webapp. If this is /somespecificpath, then the cookie is only available in pages under the specified path.
maxAge - The maximum age of the cookie, in seconds. If this is 0, then the cookie will be removed. Note that the name and path must be exactly the same as it was when the cookie was created. If this is -1 then the cookie will become a session cookie and thus live as long as the established HTTP session.
Throws:
java.lang.UnsupportedOperationException - If UTF-8 is not supported on this machine.
See Also:
ExternalContext.addResponseCookie(String, String, Map)

removeResponseCookie

public static void removeResponseCookie(java.lang.String name,
                                        java.lang.String path)
Remove the cookie with given name and path from the HTTP response. Note that the name and path must be exactly the same as it was when the cookie was created.

Parameters:
name - The cookie name.
path - The cookie path.
See Also:
ExternalContext.addResponseCookie(String, String, Map)

getSession

public static javax.servlet.http.HttpSession getSession()
Returns the HTTP session and creates one if one doesn't exist.

Note that whenever you absolutely need this method to perform a general task, you might want to consider to submit a feature request to OmniFaces in order to add a new utility method which performs exactly this general task.

Returns:
The HTTP session.
See Also:
ExternalContext.getSession(boolean)

getSession

public static javax.servlet.http.HttpSession getSession(boolean create)
Returns the HTTP session and creates one if one doesn't exist and create argument is true, otherwise don't create one and return null.

Note that whenever you absolutely need this method to perform a general task, you might want to consider to submit a feature request to OmniFaces in order to add a new utility method which performs exactly this general task.

Returns:
The HTTP session.
See Also:
ExternalContext.getSession(boolean)

getSessionId

public static java.lang.String getSessionId()
Returns a string containing the unique identifier assigned to this session. The identifier is assigned by the servlet container and is implementation dependent.

Returns:
The HTTP session ID.
Since:
1.2
See Also:
HttpSession.getId()

invalidateSession

public static void invalidateSession()
Invalidates the current HTTP session. So, any subsequent HTTP request will get a new one when necessary.

See Also:
ExternalContext.invalidateSession()

hasSession

public static boolean hasSession()
Returns whether the HTTP session has already been created.

Returns:
true if the HTTP session has already been created, otherwise false.
Since:
1.1
See Also:
ExternalContext.getSession(boolean)

isSessionNew

public static boolean isSessionNew()
Returns whether the HTTP session has been created for the first time in the current request. This returns also false when there is no means of a HTTP session.

Returns:
true if the HTTP session has been created for the first time in the current request, otherwise false.
Since:
1.1
See Also:
ExternalContext.getSession(boolean), HttpSession.isNew()

getSessionCreationTime

public static long getSessionCreationTime()
Returns the time when the HTTP session was created, measured in epoch time. This implicitly creates the session if one doesn't exist.

Returns:
The time when the HTTP session was created.
Since:
1.1
See Also:
HttpSession.getCreationTime()

getSessionLastAccessedTime

public static long getSessionLastAccessedTime()
Returns the time of the previous request associated with the current HTTP session, measured in epoch time. This implicitly creates the session if one doesn't exist.

Returns:
The time of the previous request associated with the current HTTP session.
Since:
1.1
See Also:
HttpSession.getLastAccessedTime()

getSessionMaxInactiveInterval

public static int getSessionMaxInactiveInterval()
Returns the HTTP session timeout in seconds. This implicitly creates the session if one doesn't exist.

Returns:
The HTTP session timeout in seconds.
Since:
1.1
See Also:
HttpSession.getMaxInactiveInterval()

setSessionMaxInactiveInterval

public static void setSessionMaxInactiveInterval(int seconds)
Sets the HTTP session timeout in seconds. A value of 0 or less means that the session should never timeout. This implicitly creates the session if one doesn't exist.

Parameters:
seconds - The HTTP session timeout in seconds.
Since:
1.1
See Also:
HttpSession.setMaxInactiveInterval(int)

hasSessionTimedOut

public static boolean hasSessionTimedOut()
Returns whether the HTTP session has been timed out for the current request. This is helpful if you need to distinguish between a first-time request on a fresh session and a first-time request on a timed out session, for example to display "Oops, you have been logged out because your session has been timed out!".

Returns:
true if the HTTP session has been timed out for the current request, otherwise false.
Since:
1.1
See Also:
HttpServletRequest.getRequestedSessionId(), HttpServletRequest.isRequestedSessionIdValid()

getServletContext

public static javax.servlet.ServletContext getServletContext()
Returns the servlet context.

Note that whenever you absolutely need this method to perform a general task, you might want to consider to submit a feature request to OmniFaces in order to add a new utility method which performs exactly this general task.

Returns:
the servlet context.
See Also:
ExternalContext.getContext()

getInitParameterMap

public static java.util.Map<java.lang.String,java.lang.String> getInitParameterMap()
Returns the application initialization parameter map. This returns the parameter name-value pairs of all <context-param> entries in in web.xml.

Returns:
The application initialization parameter map.
Since:
1.1
See Also:
ExternalContext.getInitParameterMap()

getInitParameter

public static java.lang.String getInitParameter(java.lang.String name)
Returns the application initialization parameter. This returns the <param-value> of a <context-param> in web.xml associated with the given <param-name>.

Parameters:
name - The application initialization parameter name.
Returns:
The application initialization parameter value associated with the given name, or null if there is none.
Since:
1.1
See Also:
ExternalContext.getInitParameter(String)

getMimeType

public static java.lang.String getMimeType(java.lang.String name)
Returns the mime type for the given file name. The mime type is determined based on file extension and configureable by <mime-mapping> entries in web.xml. When the mime type is unknown, then a default of application/octet-stream will be returned.

Parameters:
name - The file name to return the mime type for.
Returns:
The mime type for the given file name.
See Also:
ExternalContext.getMimeType(String)

getResource

public static java.net.URL getResource(java.lang.String path)
                                throws java.net.MalformedURLException
Returns a URL for an application resource mapped to the specified path, if it exists; otherwise, return null.

Parameters:
path - The application resource path to return an input stream for.
Returns:
An input stream for an application resource mapped to the specified path.
Throws:
java.net.MalformedURLException
Since:
1.2
See Also:
ExternalContext.getResource(String)

getResourceAsStream

public static java.io.InputStream getResourceAsStream(java.lang.String path)
Returns an input stream for an application resource mapped to the specified path, if it exists; otherwise, return null.

Parameters:
path - The application resource path to return an input stream for.
Returns:
An input stream for an application resource mapped to the specified path.
See Also:
ExternalContext.getResourceAsStream(String)

getResourcePaths

public static java.util.Set<java.lang.String> getResourcePaths(java.lang.String path)
Returns a set of available application resource paths matching the specified path.

Parameters:
path - The partial application resource path used to return matching resource paths.
Returns:
A set of available application resource paths matching the specified path.
See Also:
ExternalContext.getResourcePaths(String)

getRealPath

public static java.lang.String getRealPath(java.lang.String webContentPath)
Returns the absolute disk file system path representation of the given web content path. This thus converts the given path of a web content resource (e.g. /index.xhtml) to an absolute disk file system path (e.g. /path/to/server/work/folder/some.war/index.xhtml) which can then be used in File, FileInputStream, etc.

Note that this will return null when the WAR is not expanded into the disk file system, but instead into memory. If all you want is just an InputStream of the web content resource, then better use getResourceAsStream(String) instead.

Also note that it wouldn't make sense to modify or create files in this location, as those changes would get lost anyway when the WAR is redeployed or even when the server is restarted. This is thus absolutely not a good location to store for example uploaded files.

Parameters:
webContentPath - The web content path to be converted to an absolute disk file system path.
Returns:
The absolute disk file system path representation of the given web content path.
Since:
1.2

getRequestMap

public static java.util.Map<java.lang.String,java.lang.Object> getRequestMap()
Returns the request scope map.

Returns:
The request scope map.
See Also:
ExternalContext.getRequestMap()

getRequestAttribute

public static <T> T getRequestAttribute(java.lang.String name)
Returns the request scope attribute value associated with the given name.

Parameters:
name - The request scope attribute name.
Returns:
The request scope attribute value associated with the given name.
Throws:
java.lang.ClassCastException - When T is of wrong type.
See Also:
ExternalContext.getRequestMap()

setRequestAttribute

public static void setRequestAttribute(java.lang.String name,
                                       java.lang.Object value)
Sets the request scope attribute value associated with the given name.

Parameters:
name - The request scope attribute name.
value - The request scope attribute value.
See Also:
ExternalContext.getRequestMap()

removeRequestAttribute

public static <T> T removeRequestAttribute(java.lang.String name)
Removes the request scope attribute value associated with the given name.

Parameters:
name - The request scope attribute name.
Returns:
The request scope attribute value previously associated with the given name, or null if there is no such attribute.
Throws:
java.lang.ClassCastException - When T is of wrong type.
Since:
1.1
See Also:
ExternalContext.getRequestMap()

getRequestAttribute

public static <T> T getRequestAttribute(javax.faces.context.FacesContext context,
                                        java.lang.String name)
Returns the request scope attribute value associated with the given name.

Parameters:
context - The faces context used for looking up the attribute.
name - The request scope attribute name.
Returns:
The request scope attribute value associated with the given name.
Throws:
java.lang.ClassCastException - When T is of wrong type.
Since:
1.4
See Also:
ExternalContext.getRequestMap()

getFlash

public static javax.faces.context.Flash getFlash()
Returns the flash scope. Note that Flash implements Map<String, Object>, so you can just treat it like a Map<String, Object>.

Returns:
The flash scope.
See Also:
ExternalContext.getFlash()

getFlashAttribute

public static <T> T getFlashAttribute(java.lang.String name)
Returns the flash scope attribute value associated with the given name.

Parameters:
name - The flash scope attribute name.
Returns:
The flash scope attribute value associated with the given name.
Throws:
java.lang.ClassCastException - When T is of wrong type.
See Also:
ExternalContext.getFlash()

setFlashAttribute

public static void setFlashAttribute(java.lang.String name,
                                     java.lang.Object value)
Sets the flash scope attribute value associated with the given name.

Parameters:
name - The flash scope attribute name.
value - The flash scope attribute value.
See Also:
ExternalContext.getFlash()

removeFlashAttribute

public static <T> T removeFlashAttribute(java.lang.String name)
Removes the flash scope attribute value associated with the given name.

Parameters:
name - The flash scope attribute name.
Returns:
The flash scope attribute value previously associated with the given name, or null if there is no such attribute.
Throws:
java.lang.ClassCastException - When T is of wrong type.
Since:
1.1
See Also:
ExternalContext.getFlash()

getViewMap

public static java.util.Map<java.lang.String,java.lang.Object> getViewMap()
Returns the view scope map.

Returns:
The view scope map.
See Also:
UIViewRoot.getViewMap()

getViewAttribute

public static <T> T getViewAttribute(java.lang.String name)
Returns the view scope attribute value associated with the given name.

Parameters:
name - The view scope attribute name.
Returns:
The view scope attribute value associated with the given name.
Throws:
java.lang.ClassCastException - When T is of wrong type.
See Also:
UIViewRoot.getViewMap()

setViewAttribute

public static void setViewAttribute(java.lang.String name,
                                    java.lang.Object value)
Sets the view scope attribute value associated with the given name.

Parameters:
name - The view scope attribute name.
value - The view scope attribute value.
See Also:
UIViewRoot.getViewMap()

removeViewAttribute

public static <T> T removeViewAttribute(java.lang.String name)
Removes the view scope attribute value associated with the given name.

Parameters:
name - The view scope attribute name.
Returns:
The view scope attribute value previously associated with the given name, or null if there is no such attribute.
Throws:
java.lang.ClassCastException - When T is of wrong type.
Since:
1.1
See Also:
UIViewRoot.getViewMap()

getSessionMap

public static java.util.Map<java.lang.String,java.lang.Object> getSessionMap()
Returns the session scope map.

Returns:
The session scope map.
See Also:
ExternalContext.getSessionMap()

getSessionAttribute

public static <T> T getSessionAttribute(java.lang.String name)
Returns the session scope attribute value associated with the given name.

Parameters:
name - The session scope attribute name.
Returns:
The session scope attribute value associated with the given name.
Throws:
java.lang.ClassCastException - When T is of wrong type.
See Also:
ExternalContext.getSessionMap()

setSessionAttribute

public static void setSessionAttribute(java.lang.String name,
                                       java.lang.Object value)
Sets the session scope attribute value associated with the given name.

Parameters:
name - The session scope attribute name.
value - The session scope attribute value.
See Also:
ExternalContext.getSessionMap()

removeSessionAttribute

public static <T> T removeSessionAttribute(java.lang.String name)
Removes the session scope attribute value associated with the given name.

Parameters:
name - The session scope attribute name.
Returns:
The session scope attribute value previously associated with the given name, or null if there is no such attribute.
Throws:
java.lang.ClassCastException - When T is of wrong type.
Since:
1.1
See Also:
ExternalContext.getSessionMap()

getApplicationMap

public static java.util.Map<java.lang.String,java.lang.Object> getApplicationMap()
Returns the application scope map.

Returns:
The application scope map.
See Also:
ExternalContext.getApplicationMap()

getApplicationAttribute

public static <T> T getApplicationAttribute(java.lang.String name)
Returns the application scope attribute value associated with the given name.

Parameters:
name - The application scope attribute name.
Returns:
The application scope attribute value associated with the given name.
Throws:
java.lang.ClassCastException - When T is of wrong type.
See Also:
ExternalContext.getApplicationMap()

setApplicationAttribute

public static void setApplicationAttribute(java.lang.String name,
                                           java.lang.Object value)
Sets the application scope attribute value associated with the given name.

Parameters:
name - The application scope attribute name.
value - The application scope attribute value.
See Also:
ExternalContext.getApplicationMap()

removeApplicationAttribute

public static <T> T removeApplicationAttribute(java.lang.String name)
Removes the application scope attribute value associated with the given name.

Parameters:
name - The application scope attribute name.
Returns:
The application scope attribute value previously associated with the given name, or null if there is no such attribute.
Throws:
java.lang.ClassCastException - When T is of wrong type.
Since:
1.1
See Also:
ExternalContext.getApplicationMap()

getApplicationAttribute

public static <T> T getApplicationAttribute(javax.faces.context.FacesContext context,
                                            java.lang.String name)
Returns the application scope attribute value associated with the given name.

Parameters:
name - The application scope attribute name.
context - The faces context used for looking up the attribute.
Returns:
The application scope attribute value associated with the given name.
Throws:
java.lang.ClassCastException - When T is of wrong type.
Since:
1.4
See Also:
ExternalContext.getApplicationMap()

getApplicationAttribute

public static <T> T getApplicationAttribute(javax.servlet.ServletContext context,
                                            java.lang.String name)
Returns the application scope attribute value associated with the given name.

Parameters:
name - The application scope attribute name.
context - The servlet context used for looking up the attribute.
Returns:
The application scope attribute value associated with the given name.
Throws:
java.lang.ClassCastException - When T is of wrong type.
Since:
1.4
See Also:
ServletContext.getAttribute(String)

sendFile

public static void sendFile(java.io.File file,
                            boolean attachment)
                     throws java.io.IOException
Send the given file to the response. The content type will be determined based on file name. The content length will be set to the length of the file. The FacesContext.responseComplete() will implicitly be called after successful streaming.

Parameters:
file - The file to be sent to the response.
attachment - Whether the file should be provided as attachment, or just inline.
Throws:
java.io.IOException - Whenever something fails at I/O level. The caller should preferably not catch it, but just redeclare it in the action method. The servletcontainer will handle it.

sendFile

public static void sendFile(byte[] content,
                            java.lang.String filename,
                            boolean attachment)
                     throws java.io.IOException
Send the given byte array as a file to the response. The content type will be determined based on file name. The content length will be set to the length of the byte array. The FacesContext.responseComplete() will implicitly be called after successful streaming.

Parameters:
content - The file content as byte array.
filename - The file name which should appear in content disposition header.
attachment - Whether the file should be provided as attachment, or just inline.
Throws:
java.io.IOException - Whenever something fails at I/O level. The caller should preferably not catch it, but just redeclare it in the action method. The servletcontainer will handle it.

sendFile

public static void sendFile(java.io.InputStream content,
                            java.lang.String filename,
                            boolean attachment)
                     throws java.io.IOException
Send the given input stream as a file to the response. The content type will be determined based on file name. The content length may not be set because that's not predictable based on input stream. The client may receive a download of an unknown length and thus the download progress may be unknown to the client. Only if the input stream is smaller than the default buffer size, then the content length will be set. The InputStream.close() will implicitly be called after streaming, regardless of whether an exception is been thrown or not. The FacesContext.responseComplete() will implicitly be called after successful streaming.

Parameters:
content - The file content as input stream.
filename - The file name which should appear in content disposition header.
attachment - Whether the file should be provided as attachment, or just inline.
Throws:
java.io.IOException - Whenever something fails at I/O level. The caller should preferably not catch it, but just redeclare it in the action method. The servletcontainer will handle it.

getFacesServletRegistration

public static javax.servlet.ServletRegistration getFacesServletRegistration(javax.servlet.ServletContext servletContext)
Gets the ServletRegistration associated with the FacesServlet.

Parameters:
servletContext - the context to get the ServletRegistration from.
Returns:
ServletRegistration for FacesServlet, or null if the FacesServlet is not installed.
Since:
1.4