Interface MvcContext
-
public interface MvcContext
This class provides contextual information such as context and application paths as well as access to the Jakarta RESTful Web Services application configuration object. In addition, it provides access to the security-related beans
Csrf
andEncoders
.Implementations of this class are injectable, must be
RequestScoped
and accessible from Jakarta Expression Language using the namemvc
. For example, the CSRF token name and value can be accessed in Jakarta Expression Language using the expressionsmvc.csrf.name
andmvc.csrf.token
, respectively.- Since:
- 1.0
- Author:
- Santiago Pericas-Geertsen, Ivar Grimstad
- See Also:
Configuration
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description String
getBasePath()
Get the application's base path which is defined as the concatenation of context and application paths.jakarta.ws.rs.core.Configuration
getConfig()
Get the Jakarta RESTful Web Services 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.jakarta.ws.rs.core.UriBuilder
uriBuilder(String identifier)
Returns aUriBuilder
for building URIs to be matched by a controller method.
-
-
-
Method Detail
-
getConfig
jakarta.ws.rs.core.Configuration getConfig()
Get the Jakarta RESTful Web Services application configuration object. All application-defined properties are accessible via this object.- Returns:
- the configuration object.
-
getBasePath
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.
- Returns:
- the application's base path.
-
getCsrf
Csrf getCsrf()
Get the CSRF object.- Returns:
- the CSRF object.
-
getEncoders
Encoders getEncoders()
Get the built-in encoders.- Returns:
- instance of encoders.
-
getLocale
Locale getLocale()
Returns the locale of the current request.- Returns:
- The request locale
-
uri
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 Jakarta Server Pages:
${mvc.uri('MyController#myMethod')}
- Parameters:
identifier
- for the controller method.- Returns:
- the constructed URI including context- and application path.
-
uri
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
andMatrixParam
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 Jakarta Server Pages:
${mvc.uri('MyController#myMethod', {'foo': 'bar', 'id': 42})}
- Parameters:
identifier
- for the controller method.params
- a map of path-, query- and matrix parameters.- Returns:
- the constructed URI including context- and application path.
- Throws:
IllegalArgumentException
- if there are any URI template parameters without a supplied value, or if a value isnull
.
-
uriBuilder
jakarta.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.- Parameters:
identifier
- for the controller method.- Returns:
- a reference to a
UriBuilder
.
-
-