Module jakarta.mvc
Package jakarta.mvc

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 and Encoders.

Implementations of this class are injectable, must be 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.

Since:
1.0
See Also:
  • Configuration
  • Method Summary

    Modifier and Type
    Method
    Description
    Get the application's base path which is defined as the concatenation of context and application paths.
    jakarta.ws.rs.core.Configuration
    Get the Jakarta RESTful Web Services application configuration object.
    Get the CSRF object.
    Get the built-in encoders.
    Returns the locale of the current request.
    uri(String identifier)
    Creates an URI to be matched by a controller method.
    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 a UriBuilder for building URIs to be matched by a controller method.
  • Method Details

    • 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 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 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 is null.
    • 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.