public class

ModelMap

extends LinkedHashMap<K, V>
java.lang.Object
   ↳ java.util.AbstractMap<K, V>
     ↳ java.util.HashMap<K, V>
       ↳ java.util.LinkedHashMap<K, V>
         ↳ org.springframework.ui.ModelMap
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

Implementation of java.util.Map for use when building model data for use with UI tools. Supports chained calls and generation of model attribute names.

This class serves as generic model holder for both Servlet and Portlet MVC, but is not tied to either of those. Check out the Model interface for a Java-5-based interface variant that serves the same purpose.

Summary

Public Constructors
ModelMap()
Construct a new, empty ModelMap.
ModelMap(String attributeName, Object attributeValue)
Construct a new ModelMap containing the supplied attribute under the supplied name.
ModelMap(Object attributeValue)
Construct a new ModelMap containing the supplied attribute.
Public Methods
ModelMap addAllAttributes(Map<String, ?> attributes)
Copy all attributes in the supplied Map into this Map.
ModelMap addAllAttributes(Collection<?> attributeValues)
Copy all attributes in the supplied Collection into this Map, using attribute name generation for each element.
ModelMap addAllObjects(Map objects)
This method is deprecated. as of Spring 2.5, in favor of addAllAttributes(Map)
ModelMap addAllObjects(Collection objects)
This method is deprecated. as of Spring 2.5, in favor of addAllAttributes(Collection)
ModelMap addAttribute(Object attributeValue)
Add the supplied attribute to this Map using a generated name.
ModelMap addAttribute(String attributeName, Object attributeValue)
Add the supplied attribute under the supplied name.
ModelMap addObject(String modelName, Object modelObject)
This method is deprecated. as of Spring 2.5, in favor of addAttribute(String, Object)
ModelMap addObject(Object modelObject)
This method is deprecated. as of Spring 2.5, in favor of addAttribute(Object)
boolean containsAttribute(String attributeName)
Does this model contain an attribute of the given name?
ModelMap mergeAttributes(Map<String, ?> attributes)
Copy all attributes in the supplied Map into this Map, with existing objects of the same name taking precedence (i.e.
[Expand]
Inherited Methods
From class java.util.LinkedHashMap
From class java.util.HashMap
From class java.util.AbstractMap
From class java.lang.Object
From interface java.util.Map

Public Constructors

public ModelMap ()

Construct a new, empty ModelMap.

public ModelMap (String attributeName, Object attributeValue)

Construct a new ModelMap containing the supplied attribute under the supplied name.

public ModelMap (Object attributeValue)

Construct a new ModelMap containing the supplied attribute. Uses attribute name generation to generate the key for the supplied model object.

Public Methods

public ModelMap addAllAttributes (Map<String, ?> attributes)

Copy all attributes in the supplied Map into this Map.

public ModelMap addAllAttributes (Collection<?> attributeValues)

Copy all attributes in the supplied Collection into this Map, using attribute name generation for each element.

public ModelMap addAllObjects (Map objects)

This method is deprecated.
as of Spring 2.5, in favor of addAllAttributes(Map)

public ModelMap addAllObjects (Collection objects)

This method is deprecated.
as of Spring 2.5, in favor of addAllAttributes(Collection)

public ModelMap addAttribute (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.

Parameters
attributeValue the model attribute value (never null)

public ModelMap addAttribute (String attributeName, Object attributeValue)

Add the supplied attribute under the supplied name.

Parameters
attributeName the name of the model attribute (never null)
attributeValue the model attribute value (can be null)

public ModelMap addObject (String modelName, Object modelObject)

This method is deprecated.
as of Spring 2.5, in favor of addAttribute(String, Object)

public ModelMap addObject (Object modelObject)

This method is deprecated.
as of Spring 2.5, in favor of addAttribute(Object)

public boolean containsAttribute (String attributeName)

Does this model contain an attribute of the given name?

Parameters
attributeName the name of the model attribute (never null)
Returns
  • whether this model contains a corresponding attribute

public ModelMap mergeAttributes (Map<String, ?> attributes)

Copy all attributes in the supplied Map into this Map, with existing objects of the same name taking precedence (i.e. not getting replaced).