Top Description Methods
jakarta.mvc

public Interface MvcContext

Imports
jakarta.mvc.security.Csrf, .Encoders, jakarta.ws.rs.core.Configuration, .UriBuilder, java.net.URI, java.util.Locale, .Map

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 jakarta.mvc.security.Csrf and jakarta.mvc.security.Encoders.

Implementations of this class are injectable, must be jakarta.enterprise.context.RequestScoped and accessible from Jakarta Expression Language using the name mvc. For example, the CSRF token name and value can be accessed in Jakarta Expression Language using the expressions mvc.csrf.name and mvc.csrf.token, respectively.

Authors
Santiago Pericas-Geertsen, Ivar Grimstad
Since
1.0
See Also
jakarta.ws.rs.core.Configuration

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

the application's base path.
getBasePath
()

Get the application's base path which is defined as the concatenation of context and application paths.

public Configuration

Returns:

the configuration object.
getConfig
()

Get the Jakarta RESTful Web Services application configuration object.

public Csrf

Returns:

the CSRF object.
getCsrf
()

Get the CSRF object.

public Encoders

Returns:

instance of encoders.
getEncoders
()

Get the built-in encoders.

public String
getHiddenMethodFieldName()

Get the name of the hidden field that is required for the jakarta.mvc.form.FormMethodOverwriter.

public Locale

Returns:

The request locale
getLocale
()

Returns the locale of the current request.

public URI

Returns:

the constructed URI including context- and application path.
uri
(String
for the controller method.
identifier
)

Creates an URI to be matched by a controller method.

public URI

Returns:

the constructed URI including context- and application path.
uri
(String
for the controller method.
identifier
,
Map<String, Object>
a map of path-, query- and matrix parameters.
params
)

Creates an URI to be matched by a controller method.

public UriBuilder

Returns:

a reference to a UriBuilder.
uriBuilder
(String
for the controller method.
identifier
)

Returns a UriBuilder for building URIs to be matched by a controller method.

Method Detail

getBasePathback to summary
public 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:String

the application's base path.

getConfigback to summary
public Configuration getConfig()

Get the Jakarta RESTful Web Services application configuration object. All application-defined properties are accessible via this object.

Returns:Configuration

the configuration object.

getCsrfback to summary
public Csrf getCsrf()

Get the CSRF object.

Returns:Csrf

the CSRF object.

getEncodersback to summary
public Encoders getEncoders()

Get the built-in encoders.

Returns:Encoders

instance of encoders.

getHiddenMethodFieldNameback to summary
public String getHiddenMethodFieldName()

Get the name of the hidden field that is required for the jakarta.mvc.form.FormMethodOverwriter.

Returns:String

the custom name set by using jakarta.mvc.form.FormMethodOverwriter#HIDDEN_FIELD_NAME or the default value in jakarta.mvc.form.FormMethodOverwriter#DEFAULT_HIDDEN_FIELD_NAME.

getLocaleback to summary
public Locale getLocale()

Returns the locale of the current request.

Returns:Locale

The request locale

uriback to summary
public 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 jakarta.ws.rs.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:String

for the controller method.

Returns:URI

the constructed URI including context- and application path.

uriback to summary
public 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 jakarta.ws.rs.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 jakarta.ws.rs.PathParam, jakarta.ws.rs.QueryParam and jakarta.ws.rs.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 Jakarta Server Pages:

${mvc.uri('MyController#myMethod', {'foo': 'bar', 'id': 42})}
Parameters
identifier:String

for the controller method.

params:Map<String, Object>

a map of path-, query- and matrix parameters.

Returns:URI

the constructed URI including context- and application path.

Exceptions
IllegalArgumentException:
if there are any URI template parameters without a supplied value, or if a value is null.
uriBuilderback to summary
public 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:String

for the controller method.

Returns:UriBuilder

a reference to a UriBuilder.