Top Description Fields Constructors Methods
jakarta.faces.context

public abstract Class ExternalContext

extends Object
Class Inheritance
Known Direct Subclasses
jakarta.faces.context.ExternalContextWrapper
Imports
java.io.IOException, .InputStream, .OutputStream, .UnsupportedEncodingException, .Writer, java.net.MalformedURLException, .URL, java.security.Principal, java.util.Iterator, .List, .Locale, .Map, .Set, jakarta.faces.lifecycle.ClientWindow

This class allows the Faces API to be unaware of the nature of its containing application environment. In particular, this class allows Jakarta Faces based applications to run in either a Jakarta Servlet or a Portlet environment.

The documentation for this class only specifies the behavior for the Jakarta Servlet implementation of ExternalContext. The Portlet implementation of ExternalContext is specified under the revision of the Portlet Bridge Specification for JavaServer Faces JSR that corresponds to this version of the Jakarta Faces Specification. See the Preface of the Jakarta Faces Specification Document, for a reference.

If a reference to an ExternalContext is obtained during application startup or shutdown time, any method documented as "valid to call this method during application startup or shutdown" must be supported during application startup or shutdown time. The result of calling a method during application startup or shutdown time that does not have this designation is undefined.

An ExternalContext can be injected into a CDI managed bean using @Inject ExternalContext externalContext;

Field Summary

Modifier and TypeField and Description
public static final String
BASIC_AUTH

String identifier for BASIC authentication.

public static final String
CLIENT_CERT_AUTH

String identifier for CLIENT_CERT authentication.

private ExternalContext
public static final String
DIGEST_AUTH

String identifier for DIGEST authentication.

public static final String
FORM_AUTH

String identifier for FORM authentication.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
addResponseCookie(String
To be passed as the first argument to the Cookie constructor.
name
,
String
To be passed as the second argument to the Cookie constructor.
value
,
Map<String, Object>
A Map containg key/value pairs to be passed as arguments to the setter methods as described above.
properties
)

Adds the cookie represented by the arguments to the response.

public void
addResponseHeader(String
The name of the response header.
name
,
String
The value of the response header.
value
)

Add the given name and value to the response header.

public abstract void
dispatch(String
Context relative path to the specified resource, which must start with a slash ("/") character
path
)

Dispatch a request to the specified resource to create output for this response.

public abstract String

Returns:

the encoded URL.
encodeActionURL
(String
The input URL to be encoded
url
)

Return the input URL, after performing any rewriting needed to ensure that it will correctly identify an addressable action in the current application.

public String

Returns:

the result of encoding.
encodeBookmarkableURL
(String
The base URL onto which the query string generated by this method will be appended. The URL may contain query parameters.
baseUrl
,
Map<String, List<String>>
The collection of Parameter objects, representing name=value pairs that are used to produce a query string
parameters
)

The purpose of this method is to generate a query string from the collection of Parameter objects provided by the parameters argument and append that query string to the baseUrl.

public abstract String

Returns:

the unique name prefixed with namespace.
encodeNamespace
(String
Name to be encoded
name
)

Return the specified name, after prefixing it with a namespace that ensures that it will be unique within the context of a particular page.

public String

Returns:

the encoded URL.
encodePartialActionURL
(String
The input URL to be encoded
url
)

Return the input URL, after performing any rewriting needed to ensure that it can be used in a partial page submission (ajax request) to correctly identify an addressable action in the current application.

public String

Returns:

the result of encoding.
encodeRedirectURL
(String
The base URL onto which the query string generated by this method will be appended. The URL may contain query parameters.
baseUrl
,
Map<String, List<String>>
The collection of Parameter objects, representing name=value pairs that are used to produce a query string
parameters
)

The purpose of this method is to generate a query string from the collection of Parameter objects provided by the parameters argument and append that query string to the baseUrl.

public abstract String

Returns:

the encoded resource URL.
encodeResourceURL
(String
The input URL to be encoded
url
)

Return the input URL, after performing any rewriting needed to ensure that it will correctly identify an addressable resource in the current application.

public abstract String

Returns:

the encoded websocket URL.
encodeWebsocketURL
(String
The input URL to be encoded.
url
)

Return the websocket URL, after performing any rewriting needed to ensure that it will correctly identify an addressable websocket in the current application.

public String

Returns:

the context path of this application.
getApplicationContextPath
()

Return the name of the container context for this application.

public abstract Map<String, Object>

Returns:

the map associated with the backed ServletContext.
getApplicationMap
()

Return a mutable Map representing the application scope attributes for the current application.

public abstract String

Returns:

the authentication type.
getAuthType
()

Return the name of the authentication scheme used to authenticate the current user, if any; otherwise, return null.

public ClientWindow

Returns:

the instance of the ClientWindow.
getClientWindow
()

Return the ClientWindow set in a preceding call to setClientWindow, or null if no such call has been made.

public abstract Object

Returns:

the object of the ServletContext.
getContext
()

Return the application environment object instance for the current appication.

public String

Returns:

the name the ServletContext.
getContextName
()

Return the name of the container context for this application.

public Flash

Returns:

the Flash for this application.
getFlash
()

Return the threadsafe Flash for this application.

public abstract String

Returns:

the value of the specified parameter.
getInitParameter
(String
Name of the requested initialization parameter
name
)

Return the value of the specified application initialization parameter (if any).

public abstract Map<String, String>

Returns:

the init parameter map for this application.
getInitParameterMap
()

Return an immutable Map whose keys are the set of application initialization parameter names configured for this application, and whose values are the corresponding parameter values.

public String

Returns:

the MIME type of the file.
getMimeType
(String
The file for which the mime type should be obtained.
file
)

Returns the MIME type of the specified file or null if the MIME type is not known.

public String

Returns:

the real path for the specified virtual path.
getRealPath
(String
The context of the requested initialization parameter
path
)

Returns a String containing the real path for a given virtual path.

public abstract String

Returns:

the user name of the current request.
getRemoteUser
()

Return the login name of the user making the current request if any; otherwise, return null.

public abstract Object

Returns:

the instance of the current request.
getRequest
()

Return the environment-specific object instance for the current request.

public String

Returns:

the character encoding currently being used.
getRequestCharacterEncoding
()

Return the character encoding currently being used to interpret this request.

public int

Returns:

the content length of the current request.
getRequestContentLength
()

Return the result of calling getContentLenth() on the ServletRequest instance for this request.

public String

Returns:

the Content-Type for this request.
getRequestContentType
()

Return the MIME Content-Type for this request.

public abstract String

Returns:

the context path for this request.
getRequestContextPath
()

Return the portion of the request URI that identifies the web application context for this request.

public abstract Map<String, Object>

Returns:

the cookie map in the current request.
getRequestCookieMap
()

Return an immutable Map whose keys are the set of cookie names included in the current request, and whose values (of type jakarta.servlet.http.Cookie) are the first (or only) cookie for each cookie name returned by the underlying request.

public abstract Map<String, String>

Returns:

the header map in the current request.
getRequestHeaderMap
()

Return an immutable Map whose keys are the set of request header names included in the current request, and whose values (of type String) are the first (or only) value for each header name returned by the underlying request.

public abstract Map<String, String[]>

Returns:

the header values map in the current request.
getRequestHeaderValuesMap
()

Return an immutable Map whose keys are the set of request header names included in the current request, and whose values (of type String[]) are all of the value for each header name returned by the underlying request.

public abstract Locale

Returns:

the Locale of the current request.
getRequestLocale
()

Return the preferred Locale in which the client will accept content.

public abstract Iterator<Locale>

Returns:

the Iterator of Locales of the current request.
getRequestLocales
()

Return an Iterator over the preferred Locales specified in the request, in decreasing order of preference.

public abstract Map<String, Object>

Returns:

the map including the attributes of the current request.
getRequestMap
()

Return a mutable Map representing the request scope attributes for the current application.

public abstract Map<String, String>

Returns:

the map for the current request parameters.
getRequestParameterMap
()

Return an immutable Map whose keys are the set of request parameters names included in the current request, and whose values (of type String) are the first (or only) value for each parameter name returned by the underlying request.

public abstract Iterator<String>

Returns:

the Iterator for the names of the current request parameters.
getRequestParameterNames
()

Return an Iterator over the names of all request parameters included in the current request.

public abstract Map<String, String[]>

Returns:

the map for the parameter values of the current request.
getRequestParameterValuesMap
()

Return an immutable Map whose keys are the set of request parameters names included in the current request, and whose values (of type String[]) are all of the values for each parameter name returned by the underlying request.

public abstract String

Returns:

the path information of the current request.
getRequestPathInfo
()

Return the extra path information (if any) included in the request URI; otherwise, return null.

public String

Returns:

the name of the scheme.
getRequestScheme
()

Returns the name of the scheme used to make this request, for example, http, https, or ftp.

public String

Returns:

the host name of the server.
getRequestServerName
()

Returns the host name of the server to which the request was sent.

public int

Returns:

the port number to which the request was sent.
getRequestServerPort
()

Returns the port number to which the request was sent.

public abstract String

Returns:

the Jakarta Servlet path information of the current request.
getRequestServletPath
()

Return the Jakarta Servlet path information (if any) included in the request URI; otherwise, return null.

public abstract URL

Returns:

the URL of the resource.
getResource
(String
The path to the requested resource, which must start with a slash ("/" character
path
)

Return a URL for the application resource mapped to the specified path, if it exists; otherwise, return null.

public abstract InputStream

Returns:

the InputStream for the application resource.
getResourceAsStream
(String
The path to the requested resource, which must start with a slash ("/" character
path
)

Return an InputStream for an application resource mapped to the specified path, if it exists; otherwise, return null.

public abstract Set<String>

Returns:

the Set of resource paths for the application resources.
getResourcePaths
(String
Partial path used to match resources, which must start with a slash ("/") character
path
)

Return the Set of resource paths for all application resources whose resource path starts with the specified argument.

public abstract Object

Returns:

the instance of the current jakarta.servlet.http.HttpServletResponse.
getResponse
()

Return the environment-specific object instance for the current response.

public int

Returns:

the buffer size of the response.
getResponseBufferSize
()

Return the buffer size for the current response.

public String

Returns:

the name of the character encoding.
getResponseCharacterEncoding
()

Returns the name of the character encoding (MIME charset) used for the body sent in this response.

public String

Returns:

the MIME Content-Type for this response.
getResponseContentType
()

Return the MIME Content-Type for this response.

public OutputStream

Returns:

the OutputStream for the current response.
getResponseOutputStream
()

Returns an OutputStream suitable for writing binary data to the user-agent.

public Writer

Returns:

the Writer for the current response.
getResponseOutputWriter
()

Returns a Writer suitable for writing character data to the user-agent.

public abstract Object

Returns:

the session object of the current request.
getSession
(boolean
Flag indicating whether or not a new session should be created if there is no session associated with the current request
create
)

If the create parameter is true, create (if necessary) and return a session instance associated with the current request.

public String

Returns:

the session id for the current request.
getSessionId
(boolean
Flag indicating whether or not a new session should be created if there is no session associated with the current request
create
)

Return the id of the current session or the empty string if no session has been created and the create parameter is false.

public abstract Map<String, Object>

Returns:

the session map for the current application.
getSessionMap
()

Return a mutable Map representing the session scope attributes for the current application.

public int

Returns:

the session maximum inactive interval.
getSessionMaxInactiveInterval
()

Returns the maximum time interval, in seconds, that the Jakarta Servlet container will keep this session open between client accesses.

public abstract Principal

Returns:

the Principal object.
getUserPrincipal
()

Return the Principal object containing the name of the current authenticated user, if any; otherwise, return null.

public void
invalidateSession()

Invalidates this session then unbinds any objects bound to it.

public boolean

Returns:

the flag indicating whether the current response has been committed.
isResponseCommitted
()

Check if the current response has been committed.

public boolean

Returns:

the boolean indicating whether this request is secured.
isSecure
()

Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.

public abstract boolean

Returns:

the flag indicating whether the current user is in the specified role.
isUserInRole
(String
Logical role name to be checked
role
)

Return true if the currently authenticated user is included in the specified role.

public abstract void
log(String
Message to be logged
message
)

Log the specified message to the application object.

public abstract void
log(String
Message to be logged
message
,
Throwable
Exception to be logged
exception
)

Log the specified message and exception to the application object.

public abstract void
redirect(String
Absolute URL to which the client should be redirected
url
)

Redirect a request to the specified URL, and cause the responseComplete() method to be called on the FacesContext instance for the current request.

public abstract void
release()

Release any resources associated with this ExternalContext instance.

public void
responseFlushBuffer()

Flushes the buffered response content to the client.

public void
responseReset()

Resets the current response.

public void
responseSendError(int
an HTTP status code
statusCode
,
String
an option message to detail the cause of the code
message
)

Sends an HTTP status code with message.

public void
setClientWindow(ClientWindow
the window with which this instance is associated.
window
)

Associate this instance with a ClientWindow.

public void
setRequest(Object
the request object to be set.
request
)

Set the environment-specific request to be returned by subsequent calls to getRequest.

public void
setRequestCharacterEncoding(String
the encoding name to be set.
encoding
)

Overrides the name of the character encoding used in the body of this request.

public void
setResponse(Object
the response instance to be set.
response
)

Set the environment-specific response to be returned by subsequent calls to getResponse.

public void
setResponseBufferSize(int
the new buffer size
size
)

Set the buffer size for the current response.

public void
setResponseCharacterEncoding(String
the character encoding to be sent by the current response.
encoding
)

Sets the character encoding (MIME charset) of the response being sent to the client, for example, to UTF-8.

public void
setResponseContentLength(int
the value to be set.
length
)

Set the content length of the response.

public void
setResponseContentType(String
The content type to be set as the contentType of the response.
contentType
)

Sets the content type of the response being sent to the client, if the response has not been committed yet.

public void
setResponseHeader(String
The name of the response header.
name
,
String
The value of the response header.
value
)

Set the response header with the given name and value.

public void
setResponseStatus(int
an HTTP status code
statusCode
)

Sets the HTTP status code for the response.

public void
setSessionMaxInactiveInterval(int
the value to be set.
interval
)

Specifies the time, in seconds, between client requests before the Jakarta Servlet container will invalidate this session.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait