org.springframework.web.servlet.mvc.support

Class RedirectAttributesModelMap

  • java.lang.Object
    • java.util.AbstractMap<K,V>
      • java.util.HashMap<K,V>
        • java.util.LinkedHashMap<java.lang.String,java.lang.Object>
  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.String,java.lang.Object>, Model, RedirectAttributes


    public class RedirectAttributesModelMap
    extends ModelMap
    implements RedirectAttributes
    A ModelMap implementation of RedirectAttributes that formats values as Strings using a DataBinder. Also provides a place to store flash attributes so they can survive a redirect without the need to be embedded in the redirect URL.
    Since:
    3.1
    Author:
    Rossen Stoyanchev
    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.AbstractMap

        java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      RedirectAttributesModelMap addAllAttributes(java.util.Collection<?> attributeValues)
      Copy all attributes in the supplied Collection into this Map, using attribute name generation for each element.
      RedirectAttributesModelMap addAllAttributes(java.util.Map<java.lang.String,?> attributes)
      Copy all attributes in the supplied Map into this Map.
      RedirectAttributesModelMap addAttribute(java.lang.Object attributeValue)
      Add the supplied attribute to this Map using a generated name.
      RedirectAttributesModelMap addAttribute(java.lang.String attributeName, java.lang.Object attributeValue)
      Add the supplied attribute under the supplied name.
      RedirectAttributes addFlashAttribute(java.lang.Object attributeValue)
      Add the given flash storage using a generated name.
      RedirectAttributes addFlashAttribute(java.lang.String attributeName, java.lang.Object attributeValue)
      Add the given flash attribute.
      java.util.Map<java.lang.String,java.lang.Object> asMap()
      Return the current set of model attributes as a Map.
      java.util.Map<java.lang.String,?> getFlashAttributes()
      Return the attributes candidate for flash storage or an empty Map.
      RedirectAttributesModelMap mergeAttributes(java.util.Map<java.lang.String,?> attributes)
      Copy all attributes in the supplied Map into this Map, with existing objects of the same name taking precedence (i.e.
      java.lang.Object put(java.lang.String key, java.lang.Object value)
      void putAll(java.util.Map<? extends java.lang.String,? extends java.lang.Object> map)
      • Methods inherited from class java.util.LinkedHashMap

        clear, containsValue, entrySet, forEach, get, getOrDefault, keySet, removeEldestEntry, replaceAll, values
      • Methods inherited from class java.util.HashMap

        clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, putIfAbsent, remove, remove, replace, replace, size
      • Methods inherited from class java.util.AbstractMap

        equals, hashCode, toString
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, containsKey, equals, hashCode, isEmpty, merge, putIfAbsent, remove, remove, replace, replace, size
    • Constructor Detail

      • RedirectAttributesModelMap

        public RedirectAttributesModelMap()
        Default constructor without a DataBinder. Attribute values are converted to String via AbstractMap.toString().
      • RedirectAttributesModelMap

        public RedirectAttributesModelMap(@Nullable
                                          DataBinder dataBinder)
        Constructor with a DataBinder.
        Parameters:
        dataBinder - used to format attribute values as Strings
    • Method Detail

      • getFlashAttributes

        public java.util.Map<java.lang.String,?> getFlashAttributes()
        Return the attributes candidate for flash storage or an empty Map.
        Specified by:
        getFlashAttributes in interface RedirectAttributes
      • addAttribute

        public RedirectAttributesModelMap addAttribute(java.lang.String attributeName,
                                                       @Nullable
                                                       java.lang.Object attributeValue)
        Add the supplied attribute under the supplied name.

        Formats the attribute value as a String before adding it.

        Specified by:
        addAttribute in interface Model
        Specified by:
        addAttribute in interface RedirectAttributes
        Overrides:
        addAttribute in class ModelMap
        Parameters:
        attributeName - the name of the model attribute (never null)
        attributeValue - the model attribute value (can be null)
      • addAttribute

        public RedirectAttributesModelMap addAttribute(java.lang.Object attributeValue)
        Add the supplied attribute to this Map using a generated name.

        Note: Empty Collections are not added to the model when using this method because we cannot correctly determine the true convention name. View code should check for null rather than for empty collections as is already done by JSTL tags.

        Formats the attribute value as a String before adding it.

        Specified by:
        addAttribute in interface Model
        Specified by:
        addAttribute in interface RedirectAttributes
        Overrides:
        addAttribute in class ModelMap
        Parameters:
        attributeValue - the model attribute value (never null)
      • asMap

        public java.util.Map<java.lang.String,java.lang.Object> asMap()
        Description copied from interface: Model
        Return the current set of model attributes as a Map.
        Specified by:
        asMap in interface Model
      • put

        public java.lang.Object put(java.lang.String key,
                                    @Nullable
                                    java.lang.Object value)

        The value is formatted as a String before being added.

        Specified by:
        put in interface java.util.Map<java.lang.String,java.lang.Object>
        Overrides:
        put in class java.util.HashMap<java.lang.String,java.lang.Object>
      • putAll

        public void putAll(@Nullable
                           java.util.Map<? extends java.lang.String,? extends java.lang.Object> map)

        Each value is formatted as a String before being added.

        Specified by:
        putAll in interface java.util.Map<java.lang.String,java.lang.Object>
        Overrides:
        putAll in class java.util.HashMap<java.lang.String,java.lang.Object>
      • addFlashAttribute

        public RedirectAttributes addFlashAttribute(java.lang.String attributeName,
                                                    @Nullable
                                                    java.lang.Object attributeValue)
        Description copied from interface: RedirectAttributes
        Add the given flash attribute.
        Specified by:
        addFlashAttribute in interface RedirectAttributes
        Parameters:
        attributeName - the attribute name; never null
        attributeValue - the attribute value; may be null