public final class Faces extends Object
FacesContext
. In effects, 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.
Modifier and Type | Method and Description |
---|---|
static void |
addRenderIds(String... clientIds)
Add the given client IDs to the collection of render IDs of the current partial view context.
|
static void |
addResponseCookie(String name,
String value,
String path,
int maxAge)
Add a cookie with given name, value, path and maxage to the HTTP response.
|
static void |
addResponseHeader(String name,
String value)
Add a header with given name and value to the HTTP response.
|
static <T> T |
evaluateExpressionGet(String expression)
Programmatically evaluate the given EL expression and return the evaluated value.
|
static void |
evaluateExpressionSet(String expression,
Object value)
Programmatically evaluate the given EL expression and set the given value.
|
static Application |
getApplication()
Returns the application singleton.
|
static <T> T |
getApplicationAttribute(String name)
Returns the application scope attribute value associated with the given name.
|
static Map<String,Object> |
getApplicationMap()
Returns the application scope map.
|
static FacesContext |
getContext()
Returns the current faces context.
|
static PhaseId |
getCurrentPhaseId()
Returns the current phase ID.
|
static Locale |
getDefaultLocale()
Returns the default locale, or
null if there is none. |
static ExternalContext |
getExternalContext()
Returns the current external context.
|
static <T> T |
getFaceletAttribute(String name)
Returns the Facelet attribute value associated with the given name.
|
static FaceletContext |
getFaceletContext()
Returns the Facelet context.
|
static Flash |
getFlash()
Returns the flash scope.
|
static <T> T |
getFlashAttribute(String name)
Returns the flash scope attribute value associated with the given name.
|
static String |
getImplInfo()
Returns the implementation information of currently loaded JSF implementation.
|
static String |
getInitParameter(String name)
Returns the application initialization parameter.
|
static Map<String,String> |
getInitParameterMap()
Returns the application initialization parameter map.
|
static Locale |
getLocale()
Returns the current locale.
|
static String |
getMapping()
Determines and returns the faces servlet mapping used in the current request.
|
static String |
getMimeType(String name)
Returns the mime type for the given file name.
|
static PartialViewContext |
getPartialViewContext()
Returns the current partial view context (the ajax context).
|
static String |
getRemoteUser()
Returns the name of the logged-in user for container managed FORM based authentication, if any.
|
static HttpServletRequest |
getRequest()
Returns the HTTP servlet request.
|
static <T> T |
getRequestAttribute(String name)
Returns the request scope attribute value associated with the given name.
|
static String |
getRequestBaseURL()
Returns the HTTP request base URL.
|
static String |
getRequestContextPath()
Returns the HTTP request context path.
|
static String |
getRequestCookie(String name)
Returns the value of the HTTP request cookie associated with the given name.
|
static String |
getRequestDomainURL()
Returns the HTTP request domain URL.
|
static String |
getRequestHeader(String name)
Returns the HTTP request header value associated with the given name.
|
static Map<String,String> |
getRequestHeaderMap()
Returns the HTTP request header map.
|
static String[] |
getRequestHeaderValues(String name)
Returns the HTTP request header values associated with the given name.
|
static Map<String,String[]> |
getRequestHeaderValuesMap()
Returns the HTTP request header values map.
|
static Map<String,Object> |
getRequestMap()
Returns the request scope map.
|
static String |
getRequestParameter(String name)
Returns the HTTP request parameter value associated with the given name.
|
static Map<String,String> |
getRequestParameterMap()
Returns the HTTP request parameter map.
|
static String[] |
getRequestParameterValues(String name)
Returns the HTTP request parameter values associated with the given name.
|
static Map<String,String[]> |
getRequestParameterValuesMap()
Returns the HTTP request parameter values map.
|
static String |
getRequestPathInfo()
Returns the HTTP request path info.
|
static String |
getRequestQueryString()
Returns the HTTP request query string.
|
static String |
getRequestServletPath()
Returns the HTTP request servlet path.
|
static String |
getRequestURI()
Returns the HTTP request URI.
|
static String |
getRequestURL()
Returns the HTTP request URL.
|
static InputStream |
getResourceAsStream(String path)
Returns an input stream for an application resource mapped to the specified path, if it exists; otherwise,
return
null . |
static Set<String> |
getResourcePaths(String path)
Returns a set of available application resource paths matching the specified path.
|
static HttpServletResponse |
getResponse()
Returns the HTTP servlet response.
|
static String |
getServerInfo()
Returns the server information of currently running application server implementation.
|
static ServletContext |
getServletContext()
Returns the servlet context.
|
static HttpSession |
getSession()
Returns the HTTP session and creates one if one doesn't exist.
|
static 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(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 long |
getSessionLastAccessedTime()
Returns the time of the previous request associated with the current HTTP session, measured in epoch time.
|
static Map<String,Object> |
getSessionMap()
Returns the session scope map.
|
static int |
getSessionMaxInactiveInterval()
Returns the HTTP session timeout in seconds.
|
static List<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(String name)
Returns the view scope attribute value associated with the given name.
|
static String |
getViewId()
Returns the ID of the current view root, or
null if there is no view. |
static Map<String,Object> |
getViewMap()
Returns the view scope map.
|
static Collection<UIViewParameter> |
getViewParameters()
Returns the view parameters of the current view, or an empty collection if there is no view.
|
static 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(UIComponent component,
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(String mapping)
Returns whether the faces servlet mapping used in the current request is a prefix mapping.
|
static boolean |
isResponseCommitted()
Returns whether the response is already committed.
|
static boolean |
isSessionNew()
Returns whether the HTTP session has been created for the first time in the current request.
|
static boolean |
isUserInRole(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(String username,
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(String outcome)
Perform the JSF navigation to the given outcome.
|
static String |
normalizeViewId(String path)
Normalize the given path as a valid view ID based on the current mapping, if necessary.
|
static void |
redirect(String url)
Sends a temporary (302) redirect to the given URL.
|
static void |
redirectPermanent(String url)
Sends a permanent (301) redirect to the given URL.
|
static <T> T |
removeApplicationAttribute(String name)
Removes the application scope attribute value associated with the given name.
|
static <T> T |
removeFlashAttribute(String name)
Removes the flash scope attribute value associated with the given name.
|
static <T> T |
removeRequestAttribute(String name)
Removes the request scope attribute value associated with the given name.
|
static void |
removeResponseCookie(String name,
String path)
Remove the cookie with given name and path from the HTTP response.
|
static <T> T |
removeSessionAttribute(String name)
Removes the session scope attribute value associated with the given name.
|
static <T> T |
removeViewAttribute(String name)
Removes the view scope attribute value associated with the given name.
|
static void |
responseReset()
Resets the current response.
|
static void |
responseSendError(int status,
String message)
Sends a HTTP response error with the given status and message.
|
static void |
sendFile(byte[] content,
String filename,
boolean attachment)
Send the given byte array as a file to the response.
|
static void |
sendFile(File file,
boolean attachment)
Send the given file to the response.
|
static void |
sendFile(InputStream content,
String filename,
boolean attachment)
Send the given input stream as a file to the response.
|
static void |
setApplicationAttribute(String name,
Object value)
Sets the application scope attribute value associated with the given name.
|
static void |
setFaceletAttribute(String name,
Object value)
Sets the Facelet attribute value associated with the given name.
|
static void |
setFlashAttribute(String name,
Object value)
Sets the flash scope attribute value associated with the given name.
|
static void |
setRequestAttribute(String name,
Object value)
Sets the request scope attribute value associated with the given name.
|
static void |
setSessionAttribute(String name,
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(String name,
Object value)
Sets the view scope attribute value associated with the given name.
|
static void |
setViewRoot(String viewId)
Sets the current view root to the given view ID.
|
public static FacesContext getContext()
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.
FacesContext.getCurrentInstance()
public static ExternalContext getExternalContext()
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.
FacesContext.getExternalContext()
public static PartialViewContext getPartialViewContext()
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.
FacesContext.getPartialViewContext()
public static Application getApplication()
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.
FacesContext.getApplication()
public static String getImplInfo()
Package.getImplementationTitle()
,
Package.getImplementationVersion()
public static String getServerInfo()
ServletContext.getServerInfo()
public static boolean isDevelopment()
true
if we're in development stage, otherwise false
.Application.getProjectStage()
public static String getMapping()
getRequestPathInfo()
,
getRequestServletPath()
public static boolean isPrefixMapping()
true
if the faces servlet mapping used in the current request is a prefix mapping, otherwise
false
.getMapping()
,
isPrefixMapping(String)
public static boolean isPrefixMapping(String mapping)
isPrefixMapping()
when you already have obtained the mapping from getMapping()
so that the mapping won't be calculated twice.mapping
- The mapping to be tested.true
if the faces servlet mapping used in the current request is a prefix mapping, otherwise
false
.NullPointerException
- When mapping is null
.public static PhaseId getCurrentPhaseId()
FacesContext.getCurrentPhaseId()
public static <T> T evaluateExpressionGet(String expression)
T
- The expected return type.expression
- The EL expression to be evaluated.ClassCastException
- When T
is of wrong type.Application.evaluateExpressionGet(FacesContext, String, Class)
public static void evaluateExpressionSet(String expression, Object value)
expression
- The EL expression to be evaluated.value
- The value to be set in the property behind the EL expression.Application.getExpressionFactory()
,
ExpressionFactory.createValueExpression(ELContext, String, Class)
,
ValueExpression.setValue(ELContext, Object)
public static UIViewRoot getViewRoot()
FacesContext.getViewRoot()
public static void setViewRoot(String viewId)
viewId
- The ID of the view which needs to be set as the current view root.ViewHandler.createView(FacesContext, String)
,
FacesContext.setViewRoot(UIViewRoot)
public static String getViewId()
null
if there is no view.null
if there is no view.UIViewRoot.getViewId()
public static String normalizeViewId(String path)
path
- The path to be normalized as a valid view ID based on the current mapping.getMapping()
,
isPrefixMapping(String)
public static Collection<UIViewParameter> getViewParameters()
ViewMetadata.getViewParameters(UIViewRoot)
public static Locale getLocale()
UIViewRoot.getLocale()
,
ExternalContext.getRequestLocale()
,
Application.getDefaultLocale()
,
Locale.getDefault()
public static Locale getDefaultLocale()
null
if there is none.null
if there is none.Application.getDefaultLocale()
public static List<Locale> getSupportedLocales()
Application.getDefaultLocale()
,
Application.getSupportedLocales()
public static void navigate(String outcome)
outcome
- The navigation outcome.Application.getNavigationHandler()
,
NavigationHandler.handleNavigation(FacesContext, String, String)
public static void addRenderIds(String... clientIds)
:
.clientIds
- The client IDs to be added to the collection of render IDs of the current partial view context.public static FaceletContext getFaceletContext()
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.
FaceletContext
public static void includeFacelet(UIComponent component, String path) throws IOException
<ui:include>
. The path is relative to the current view ID and absolute to the
webcontent root.component
- The component to include the Facelet file in.path
- The (relative) path to the Facelet file.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.FaceletContext.includeFacelet(UIComponent, String)
public static <T> T getFaceletAttribute(String name)
<ui:param>
which is been declared inside the Facelet file, or is been passed into the Facelet
file by e.g. an <ui:include>
.name
- The Facelet attribute name.ClassCastException
- When T
is of wrong type.FaceletContext.getAttribute(String)
public static void setFaceletAttribute(String name, Object value)
<ui:param>
which is been declared inside the Facelet file, or is been passed into the Facelet
file by e.g. an <ui:include>
.name
- The Facelet attribute name.value
- The Facelet attribute value.FaceletContext.setAttribute(String, Object)
public static HttpServletRequest getRequest()
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.
ExternalContext.getRequest()
public static boolean isAjaxRequest()
true
for an ajax request, false
for a non-ajax (synchronous) request.PartialViewContext.isAjaxRequest()
public static boolean isPostback()
true
for a postback, false
for a non-postback (GET) request.FacesContext.isPostback()
public static boolean isValidationFailed()
true
if the validations phase of the current request has failed, otherwise
false
.FacesContext.isValidationFailed()
public static Map<String,String> getRequestParameterMap()
ExternalContext.getRequestParameterMap()
public static String getRequestParameter(String name)
name
- The HTTP request parameter name.ExternalContext.getRequestParameterMap()
public static Map<String,String[]> getRequestParameterValuesMap()
ExternalContext.getRequestParameterValuesMap()
public static String[] getRequestParameterValues(String name)
name
- The HTTP request parameter name.ExternalContext.getRequestParameterValuesMap()
public static Map<String,String> getRequestHeaderMap()
ExternalContext.getRequestHeaderMap()
public static String getRequestHeader(String name)
name
- The HTTP request header name.ExternalContext.getRequestHeaderMap()
public static Map<String,String[]> getRequestHeaderValuesMap()
ExternalContext.getRequestHeaderValuesMap()
public static String[] getRequestHeaderValues(String name)
name
- The HTTP request header name.ExternalContext.getRequestHeaderValuesMap()
public static String getRequestContextPath()
ExternalContext.getRequestContextPath()
public static String getRequestServletPath()
ExternalContext.getRequestServletPath()
public static String getRequestPathInfo()
null
.ExternalContext.getRequestPathInfo()
public static String getRequestBaseURL()
<base>
tag.HttpServletRequest.getRequestURL()
,
HttpServletRequest.getRequestURI()
,
HttpServletRequest.getContextPath()
public static String getRequestDomainURL()
HttpServletRequest.getRequestURL()
,
HttpServletRequest.getRequestURI()
public static String getRequestURL()
HttpServletRequest.getRequestURL()
public static String getRequestURI()
HttpServletRequest.getRequestURI()
public static String getRequestQueryString()
HttpServletRequest.getQueryString()
public static HttpServletResponse getResponse()
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.
ExternalContext.getResponse()
public static void redirect(String url) throws IOException
url
- The URL to redirect the current response to.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.NullPointerException
- When url is null
.ExternalContext.redirect(String)
public static void redirectPermanent(String url) throws IOException
url
- The URL to redirect the current response to.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.NullPointerException
- When url is null
.ExternalContext.setResponseStatus(int)
,
ExternalContext.setResponseHeader(String, String)
public static void responseSendError(int status, String message) throws IOException
<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.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.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.ExternalContext.responseSendError(int, String)
public static void addResponseHeader(String name, String value)
name
- The header name.value
- The header value.ExternalContext.addResponseHeader(String, String)
public static boolean isResponseCommitted()
true
if the response is already committed, otherwise false
.ExternalContext.isResponseCommitted()
public static void responseReset()
IllegalStateException
- When the response is already committed.ExternalContext.responseReset()
public static void login(String username, String password) throws ServletException
username
- The login username.password
- The login password.ServletException
- When the login is invalid, or when container managed FORM based authentication is not
enabled.HttpServletRequest.login(String, String)
public static void logout() throws ServletException
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)
for this.ServletException
- When the logout has failed.HttpServletRequest.logout()
public static String getRemoteUser()
ExternalContext.getRemoteUser()
public static boolean isUserInRole(String role)
role
- The role to be checked on the currently logged-in user.true
if the currently logged-in user has the given role, otherwise false
.ExternalContext.isUserInRole(String)
public static String getRequestCookie(String name)
name
- The HTTP request cookie name.UnsupportedOperationException
- If UTF-8 is not supported on this machine.ExternalContext.getRequestCookieMap()
public static void addResponseCookie(String name, String value, String path, int maxAge)
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.UnsupportedOperationException
- If UTF-8 is not supported on this machine.ExternalContext.addResponseCookie(String, String, Map)
public static void removeResponseCookie(String name, String path)
name
- The cookie name.path
- The cookie path.ExternalContext.addResponseCookie(String, String, Map)
public static HttpSession getSession()
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.
ExternalContext.getSession(boolean)
public static HttpSession getSession(boolean create)
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.
ExternalContext.getSession(boolean)
public static void invalidateSession()
ExternalContext.invalidateSession()
public static boolean hasSession()
true
if the HTTP session has already been created, otherwise false
.ExternalContext.getSession(boolean)
public static boolean isSessionNew()
false
when there is no means of a HTTP session.true
if the HTTP session has been created for the first time in the current request,
otherwise false
.ExternalContext.getSession(boolean)
,
HttpSession.isNew()
public static long getSessionCreationTime()
HttpSession.getCreationTime()
public static long getSessionLastAccessedTime()
HttpSession.getLastAccessedTime()
public static int getSessionMaxInactiveInterval()
HttpSession.getMaxInactiveInterval()
public static void setSessionMaxInactiveInterval(int seconds)
seconds
- The HTTP session timeout in seconds.HttpSession.setMaxInactiveInterval(int)
public static boolean hasSessionTimedOut()
true
if the HTTP session has been timed out for the current request, otherwise
false
.HttpServletRequest.getRequestedSessionId()
,
HttpServletRequest.isRequestedSessionIdValid()
public static ServletContext getServletContext()
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.
ExternalContext.getContext()
public static Map<String,String> getInitParameterMap()
<context-param>
entries in in web.xml
.ExternalContext.getInitParameterMap()
public static String getInitParameter(String name)
<param-value>
of a
<context-param>
in web.xml
associated with the given
<param-name>
.name
- The application initialization parameter name.ExternalContext.getInitParameter(String)
public static String getMimeType(String name)
<mime-mapping>
entries in web.xml. When the mime type is unknown,
then a default of application/octet-stream will be returned.name
- The file name to return the mime type for.ExternalContext.getMimeType(String)
public static InputStream getResourceAsStream(String path)
null
.path
- The application resource path to return an input stream for.ExternalContext.getResourceAsStream(String)
public static Set<String> getResourcePaths(String path)
path
- The partial application resource path used to return matching resource paths.ExternalContext.getResourcePaths(String)
public static Map<String,Object> getRequestMap()
ExternalContext.getRequestMap()
public static <T> T getRequestAttribute(String name)
name
- The request scope attribute name.ClassCastException
- When T
is of wrong type.ExternalContext.getRequestMap()
public static void setRequestAttribute(String name, Object value)
name
- The request scope attribute name.value
- The request scope attribute value.ExternalContext.getRequestMap()
public static <T> T removeRequestAttribute(String name)
name
- The request scope attribute name.null
if
there is no such attribute.ClassCastException
- When T
is of wrong type.ExternalContext.getRequestMap()
public static Flash getFlash()
Flash
implements Map<String, Object>
, so you
can just treat it like a Map<String, Object>
.ExternalContext.getFlash()
public static <T> T getFlashAttribute(String name)
name
- The flash scope attribute name.ClassCastException
- When T
is of wrong type.ExternalContext.getFlash()
public static void setFlashAttribute(String name, Object value)
name
- The flash scope attribute name.value
- The flash scope attribute value.ExternalContext.getFlash()
public static <T> T removeFlashAttribute(String name)
name
- The flash scope attribute name.null
if
there is no such attribute.ClassCastException
- When T
is of wrong type.ExternalContext.getFlash()
public static Map<String,Object> getViewMap()
UIViewRoot.getViewMap()
public static <T> T getViewAttribute(String name)
name
- The view scope attribute name.ClassCastException
- When T
is of wrong type.UIViewRoot.getViewMap()
public static void setViewAttribute(String name, Object value)
name
- The view scope attribute name.value
- The view scope attribute value.UIViewRoot.getViewMap()
public static <T> T removeViewAttribute(String name)
name
- The view scope attribute name.null
if
there is no such attribute.ClassCastException
- When T
is of wrong type.UIViewRoot.getViewMap()
public static Map<String,Object> getSessionMap()
ExternalContext.getSessionMap()
public static <T> T getSessionAttribute(String name)
name
- The session scope attribute name.ClassCastException
- When T
is of wrong type.ExternalContext.getSessionMap()
public static void setSessionAttribute(String name, Object value)
name
- The session scope attribute name.value
- The session scope attribute value.ExternalContext.getSessionMap()
public static <T> T removeSessionAttribute(String name)
name
- The session scope attribute name.null
if
there is no such attribute.ClassCastException
- When T
is of wrong type.ExternalContext.getSessionMap()
public static Map<String,Object> getApplicationMap()
ExternalContext.getApplicationMap()
public static <T> T getApplicationAttribute(String name)
name
- The application scope attribute name.ClassCastException
- When T
is of wrong type.ExternalContext.getApplicationMap()
public static void setApplicationAttribute(String name, Object value)
name
- The application scope attribute name.value
- The application scope attribute value.ExternalContext.getApplicationMap()
public static <T> T removeApplicationAttribute(String name)
name
- The application scope attribute name.null
if
there is no such attribute.ClassCastException
- When T
is of wrong type.ExternalContext.getApplicationMap()
public static void sendFile(File file, boolean attachment) throws IOException
FacesContext.responseComplete()
will implicitly be called
after successful streaming.file
- The file to be sent to the response.attachment
- Whether the file should be provided as attachment, or just inline.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.public static void sendFile(byte[] content, String filename, boolean attachment) throws IOException
FacesContext.responseComplete()
will
implicitly be called after successful streaming.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.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.public static void sendFile(InputStream content, String filename, boolean attachment) throws IOException
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.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.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.