public interface MvcContext
This class provides contextual information such as context and application
paths as well as access to the JAX-RS application configuration object.
In addition, it provides access to the security-related beans Csrf
and Encoders
.
Implementations of this class are injectable, must be
RequestScoped
and accessible from EL using
the name mvc
. For example, the CSRF token name and value can be
accessed in EL using the expressions mvc.csrf.name
and mvc.csrf.token
, respectively.
Configuration
Modifier and Type | Method and Description |
---|---|
String |
getBasePath()
Get the application's base path which is defined as the concatenation of context
and application paths.
|
javax.ws.rs.core.Configuration |
getConfig()
Get the JAX-RS application configuration object.
|
Csrf |
getCsrf()
Get the CSRF object.
|
Encoders |
getEncoders()
Get the built-in encoders.
|
Locale |
getLocale()
Returns the locale of the current request.
|
URI |
uri(String identifier)
Creates an URI to be matched by a controller method.
|
URI |
uri(String identifier,
Map<String,Object> params)
Creates an URI to be matched by a controller method.
|
javax.ws.rs.core.UriBuilder |
uriBuilder(String identifier)
Returns a
UriBuilder for building URIs to be matched
by a controller method. |
javax.ws.rs.core.Configuration getConfig()
String getBasePath()
Get the application's base path which is defined as the concatenation of context and application paths. It follows that the value returned by this method always starts with a slash but never ends with one.
Csrf getCsrf()
Encoders getEncoders()
Locale getLocale()
URI uri(String identifier)
Creates an URI to be matched by a controller method. This is aimed primarily
for use in view rendering technologies to avoid duplicating the values of the
Path
annotations.
The controller method can either be identified by the simple name of the controller class
and the method name separated by '#' (MyController#myMethod) or by the value
of the UriRef
annotation.
The created URI includes context- and application path.
This method assumes that there is no parameter in the URI-template.
For example in JSP:
${mvc.uri('MyController#myMethod')}
identifier
- for the controller method.URI uri(String identifier, Map<String,Object> params)
Creates an URI to be matched by a controller method. This is aimed primarily
for use in view rendering technologies to avoid duplicating the values of the
Path
annotations.
The controller method can either be identified by the simple name of the controller class
and the method name separated by '#' (MyController#myMethod) or by the value
of the UriRef
annotation.
The created URI includes context- and application path.
Any PathParam
, QueryParam
and MatrixParam
which could apply for given target
method will be replaced if a matching key is found in the supplied Map.
Please note that the map must contain values for all path parameters
as they are required for building the URI. All other parameters are optional.
For example in JSP:
${mvc.uri('MyController#myMethod', {'foo': 'bar', 'id': 42})}
identifier
- for the controller method.params
- a map of path-, query- and matrix parameters.IllegalArgumentException
- if there are any URI template parameters without a supplied value, or if a value is null
.javax.ws.rs.core.UriBuilder uriBuilder(String identifier)
Returns a UriBuilder
for building URIs to be matched
by a controller method. This is aimed primarily for use in Java classes.
The controller method can either be identified by the simple name of the controller class
and the method name separated by '#' (MyController#myMethod) or by the value
of the UriRef
annotation.
identifier
- for the controller method.UriBuilder
.Copyright © 2018 Ivar Grimstad. All rights reserved.