Module jakarta.mvc
Package jakarta.mvc

Interface Models

  • All Superinterfaces:
    java.lang.Iterable<java.lang.String>

    public interface Models
    extends java.lang.Iterable<java.lang.String>

    A map of name to model instances used by a ViewEngine to process a view. Instances implementing this interface must be injectable using Inject and are RequestScoped.

    Note that certain view engines, such as engines for Jakarta Server Pages and Facelets, support model binding via Named in which case the use of Models is optional.

    Since:
    1.0
    See Also:
    Named, RequestScoped
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      java.util.Map<java.lang.String,​java.lang.Object> asMap()
      Returns a unmodifiable view of the models map.
      java.lang.Object get​(java.lang.String name)
      Retrieve a model by name.
      <T> T get​(java.lang.String name, java.lang.Class<T> clazz)
      Retrieve a model by name in a type-safe way.
      Models put​(java.lang.String name, java.lang.Object model)
      Stores a new model in the map.
      • Methods inherited from interface java.lang.Iterable

        forEach, iterator, spliterator
    • Method Detail

      • put

        Models put​(java.lang.String name,
                   java.lang.Object model)
        Stores a new model in the map.
        Parameters:
        name - name of the model
        model - model to store in the map
        Returns:
        the current instance to allow method chaining
      • get

        java.lang.Object get​(java.lang.String name)
        Retrieve a model by name.
        Parameters:
        name - name of the model
        Returns:
        the model or null
      • get

        <T> T get​(java.lang.String name,
                  java.lang.Class<T> clazz)
        Retrieve a model by name in a type-safe way.
        Type Parameters:
        T - type of the model
        Parameters:
        name - name of the model
        clazz - type of the model
        Returns:
        The model or null
      • asMap

        java.util.Map<java.lang.String,​java.lang.Object> asMap()
        Returns a unmodifiable view of the models map.
        Returns:
        unmodifiable map