/** * {@inheritDoc} * <p>Formats the attribute value as a String before adding it. */ @Override public RedirectAttributesModelMap addAttribute(Object attributeValue) { super.addAttribute(attributeValue); return this; }
/** * Construct a new {@code ModelMap} containing the supplied attribute * under the supplied name. * @see #addAttribute(String, Object) */ public ConcurrentModel(String attributeName, Object attributeValue) { addAttribute(attributeName, attributeValue); }
/** * Does this model contain an attribute of the given name? * @param attributeName the name of the model attribute (never {@code null}) * @return whether this model contains a corresponding attribute */ public boolean containsAttribute(String attributeName) { return containsKey(attributeName); }
public String handle(Model model) { model.addAttribute("someAttr", "someAttrValue"); return "redirect:/path"; } }
@Test public void handleModelReturnValue() throws Exception { mavContainer.addAttribute("attr1", "value1"); Model returnValue = new ExtendedModelMap(); returnValue.addAttribute("attr2", "value2"); processor.handleReturnValue(returnValue , returnParamModel, mavContainer, webRequest); assertEquals("value1", mavContainer.getModel().get("attr1")); assertEquals("value2", mavContainer.getModel().get("attr2")); }
@Test public void testInnerClass() throws Exception { ModelMap map = new ModelMap(); SomeInnerClass inner = new SomeInnerClass(); map.addAttribute(inner); assertSame(inner, map.get("someInnerClass")); }
@Test public void testInnerClassWithTwoUpperCaseLetters() throws Exception { ModelMap map = new ModelMap(); UKInnerClass inner = new UKInnerClass(); map.addAttribute(inner); assertSame(inner, map.get("UKInnerClass")); }
/** * Return the underlying {@code ModelMap} instance (never {@code null}). */ public ModelMap getModelMap() { if (this.model == null) { this.model = new ModelMap(); } return this.model; }
/** * Return the attribute value for the given name, if any. * @param attributeName the name of the model attribute (never {@code null}) * @return the corresponding attribute value, or {@code null} if none * @since 5.2 */ @Nullable public Object getAttribute(String attributeName) { return get(attributeName); }
@Override public ExtendedModelMap addAllAttributes(@Nullable Collection<?> attributeValues) { super.addAllAttributes(attributeValues); return this; }
private Model initModel() { if (this.model == null) { this.model = new ExtendedModelMap(); } return this.model; }
@Override public Object put(String key, Object value) { removeBindingResultIfNecessary(key, value); return super.put(key, value); }
/** * Does this model contain an attribute of the given name? * @param attributeName the name of the model attribute (never {@code null}) * @return whether this model contains a corresponding attribute */ public boolean containsAttribute(String attributeName) { return containsKey(attributeName); }
/** * Copy all attributes in the supplied {@code Map} into this {@code Map}. * @see #addAttribute(String, Object) */ public ConcurrentModel addAllAttributes(@Nullable Map<String, ?> attributes) { if (attributes != null) { putAll(attributes); } return this; }
@Override public DefaultRenderingBuilder modelAttribute(Object value) { initModel().addAttribute(value); return this; }
@Override public RedirectAttributes addFlashAttribute(Object attributeValue) { this.flashAttributes.addAttribute(attributeValue); return this; }
/** * Construct a new {@code ModelMap} containing the supplied attribute. * Uses attribute name generation to generate the key for the supplied model * object. * @see #addAttribute(Object) */ public ConcurrentModel(Object attributeValue) { addAttribute(attributeValue); }
/** * Construct a new {@code ModelMap} containing the supplied attribute. * Uses attribute name generation to generate the key for the supplied model * object. * @see #addAttribute(Object) */ public ModelMap(Object attributeValue) { addAttribute(attributeValue); }
@Override public ExtendedModelMap addAttribute(Object attributeValue) { super.addAttribute(attributeValue); return this; }
/** * Construct a new {@code ModelMap} containing the supplied attribute * under the supplied name. * @see #addAttribute(String, Object) */ public ModelMap(String attributeName, @Nullable Object attributeValue) { addAttribute(attributeName, attributeValue); }