@Override public ExtendedModelMap addAllAttributes(@Nullable Collection<?> attributeValues) { super.addAllAttributes(attributeValues); return this; }
@Override public ExtendedModelMap addAllAttributes(@Nullable Map<String, ?> attributes) { super.addAllAttributes(attributes); return this; }
/** * {@inheritDoc} * <p>Each attribute value is formatted as a String before being added. */ @Override public RedirectAttributesModelMap addAllAttributes(@Nullable Collection<?> attributeValues) { super.addAllAttributes(attributeValues); return this; }
@Override public ExtendedModelMap addAllAttributes(@Nullable Collection<?> attributeValues) { super.addAllAttributes(attributeValues); return this; }
@Override public ExtendedModelMap addAllAttributes(@Nullable Map<String, ?> attributes) { super.addAllAttributes(attributes); return this; }
/** * Copy all attributes to the underlying model. * A shortcut for {@code getModel().addAllAttributes(Map)}. */ public ModelAndViewContainer addAllAttributes(@Nullable Map<String, ?> attributes) { getModel().addAllAttributes(attributes); return this; }
/** * {@inheritDoc} * <p>Each attribute value is formatted as a String before being added. */ @Override public RedirectAttributesModelMap addAllAttributes(@Nullable Collection<?> attributeValues) { super.addAllAttributes(attributeValues); return this; }
/** * Add all attributes contained in the provided Map to the model. * @param modelMap a Map of attributeName -> attributeValue pairs * @see ModelMap#addAllAttributes(Map) * @see #getModelMap() */ public ModelAndView addAllObjects(@Nullable Map<String, ?> modelMap) { getModelMap().addAllAttributes(modelMap); return this; }
/** * Create a new ModelAndView given a view name and a model. * @param viewName name of the View to render, to be resolved * by the DispatcherServlet's ViewResolver * @param model a Map of model names (Strings) to model objects * (Objects). Model entries may not be {@code null}, but the * model Map may be {@code null} if there is no model data. */ public ModelAndView(String viewName, @Nullable Map<String, ?> model) { this.view = viewName; if (model != null) { getModelMap().addAllAttributes(model); } }
/** * Create a new ModelAndView given a View object and a model. * <em>Note: the supplied model data is copied into the internal * storage of this class. You should not consider to modify the supplied * Map after supplying it to this class</em> * @param view the View object to render * @param model a Map of model names (Strings) to model objects * (Objects). Model entries may not be {@code null}, but the * model Map may be {@code null} if there is no model data. */ public ModelAndView(View view, @Nullable Map<String, ?> model) { this.view = view; if (model != null) { getModelMap().addAllAttributes(model); } }
/** * Create a new ModelAndView given a view name, model, and HTTP status. * @param viewName name of the View to render, to be resolved * by the DispatcherServlet's ViewResolver * @param model a Map of model names (Strings) to model objects * (Objects). Model entries may not be {@code null}, but the * model Map may be {@code null} if there is no model data. * @param status an HTTP status code to use for the response * (to be set just prior to View rendering) * @since 4.3 */ public ModelAndView(@Nullable String viewName, @Nullable Map<String, ?> model, @Nullable HttpStatus status) { this.view = viewName; if (model != null) { getModelMap().addAllAttributes(model); } this.status = status; }
/** * Copy all attributes to the underlying model. * A shortcut for {@code getModel().addAllAttributes(Map)}. */ public ModelAndViewContainer addAllAttributes(@Nullable Map<String, ?> attributes) { getModel().addAllAttributes(attributes); return this; }
/** * Add all attributes contained in the provided Map to the model. * @param modelMap a Map of attributeName -> attributeValue pairs * @see ModelMap#addAllAttributes(Map) * @see #getModelMap() */ public ModelAndView addAllObjects(@Nullable Map<String, ?> modelMap) { getModelMap().addAllAttributes(modelMap); return this; }
/** * Create a new ModelAndView given a view name and a model. * @param viewName name of the View to render, to be resolved * by the DispatcherServlet's ViewResolver * @param model a Map of model names (Strings) to model objects * (Objects). Model entries may not be {@code null}, but the * model Map may be {@code null} if there is no model data. */ public ModelAndView(String viewName, @Nullable Map<String, ?> model) { this.view = viewName; if (model != null) { getModelMap().addAllAttributes(model); } }
/** * Create a new ModelAndView given a View object and a model. * <em>Note: the supplied model data is copied into the internal * storage of this class. You should not consider to modify the supplied * Map after supplying it to this class</em> * @param view the View object to render * @param model a Map of model names (Strings) to model objects * (Objects). Model entries may not be {@code null}, but the * model Map may be {@code null} if there is no model data. */ public ModelAndView(View view, @Nullable Map<String, ?> model) { this.view = view; if (model != null) { getModelMap().addAllAttributes(model); } }
/** * Create a new ModelAndView given a view name, model, and HTTP status. * @param viewName name of the View to render, to be resolved * by the DispatcherServlet's ViewResolver * @param model a Map of model names (Strings) to model objects * (Objects). Model entries may not be {@code null}, but the * model Map may be {@code null} if there is no model data. * @param status an HTTP status code to use for the response * (to be set just prior to View rendering) * @since 4.3 */ public ModelAndView(@Nullable String viewName, @Nullable Map<String, ?> model, @Nullable HttpStatus status) { this.view = viewName; if (model != null) { getModelMap().addAllAttributes(model); } this.status = status; }
@Test(expected = IllegalArgumentException.class) public void testAddAllObjectsWithSparseArrayList() throws Exception { // Null model arguments added without a name being explicitly supplied are not allowed ModelMap model = new ModelMap(); ArrayList<String> list = new ArrayList<>(); list.add("bing"); list.add(null); model.addAllAttributes(list); }
@Test public void testAddListOfTheSameObjects() throws Exception { List<TestBean> beans = new ArrayList<>(); beans.add(new TestBean("one")); beans.add(new TestBean("two")); beans.add(new TestBean("three")); ModelMap model = new ModelMap(); model.addAllAttributes(beans); assertEquals(1, model.size()); }
@Test public void testAddAllObjectsWithNullMap() throws Exception { ModelMap model = new ModelMap(); model.addAllAttributes((Map<String, ?>) null); assertEquals(0, model.size()); }
@Test public void testAddAllObjectsWithNullCollection() throws Exception { ModelMap model = new ModelMap(); model.addAllAttributes((Collection<Object>) null); assertEquals(0, model.size()); }