/** * 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); }
/** * 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}, * with existing objects of the same name taking precedence (i.e. not getting * replaced). */ public ModelMap mergeAttributes(@Nullable Map<String, ?> attributes) { if (attributes != null) { attributes.forEach((key, value) -> { if (!containsKey(key)) { put(key, value); } }); } return this; }
/** * Copy all attributes in the supplied {@code Map} into this {@code Map}, * with existing objects of the same name taking precedence (i.e. not getting * replaced). */ public ModelMap mergeAttributes(@Nullable Map<String, ?> attributes) { if (attributes != null) { attributes.forEach((key, value) -> { if (!containsKey(key)) { put(key, value); } }); } return this; }
@RequestMapping("/myPath.do") public String myHandle(@ModelAttribute(name="myCommand", binding=true) TestBean tb, BindingResult errors, ModelMap model) { FieldError error = errors.getFieldError("age"); assertNotNull("Must have field error for age property", error); assertEquals("value2", error.getRejectedValue()); if (!model.containsKey("myKey")) { model.addAttribute("myKey", "myValue"); } return "myView"; } }
@Test public void testAddMap() throws Exception { Map<String, String> map = new HashMap<>(); map.put("one", "one-value"); map.put("two", "two-value"); ModelMap model = new ModelMap(); model.addAttribute(map); assertEquals(1, model.size()); String key = StringUtils.uncapitalize(ClassUtils.getShortName(map.getClass())); assertTrue(model.containsKey(key)); }
@RequestMapping("/myPath.do") public String myHandle(@ModelAttribute("myCommand") TestBean tb, BindingResult errors, ModelMap model) { FieldError error = errors.getFieldError("age"); assertNotNull("Must have field error for age property", error); assertEquals("value2", error.getRejectedValue()); if (!model.containsKey("myKey")) { model.addAttribute("myKey", "myValue"); } return "myView"; } }
@Test public void testAddNullObjectViaCtorWithExplicitKey() throws Exception { ModelMap model = new ModelMap("foo", null); assertTrue(model.containsKey("foo")); assertNull(model.get("foo")); }
@Test public void testAddNullObjectWithExplicitKey() throws Exception { ModelMap model = new ModelMap(); model.addAttribute("foo", null); assertTrue(model.containsKey("foo")); assertNull(model.get("foo")); }
@Test public void testAopCglibProxy() throws Exception { ModelMap map = new ModelMap(); ProxyFactory factory = new ProxyFactory(); SomeInnerClass val = new SomeInnerClass(); factory.setTarget(val); factory.setProxyTargetClass(true); map.addAttribute(factory.getProxy()); assertTrue(map.containsKey("someInnerClass")); assertEquals(val, map.get("someInnerClass")); }
/** * 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); }
private boolean modelAlreadyHasUserProfile(ModelAndView modelAndView) { return modelAndView.getModelMap().containsKey(USER_PROFILE_MODEL_KEY); }
private boolean modelAlreadyHasInformation(ModelAndView modelAndView) { return modelAndView.getModelMap().containsKey(MAINTENANCE_INFORMATION_MODEL_KEY); }
/** * Copy all attributes in the supplied {@code Map} into this {@code Map}, * with existing objects of the same name taking precedence (i.e. not getting * replaced). */ public ModelMap mergeAttributes(@Nullable Map<String, ?> attributes) { if (attributes != null) { attributes.forEach((key, value) -> { if (!containsKey(key)) { put(key, value); } }); } return this; }
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView mav) { HttpSession session = request.getSession(); if (session != null) { Message message = (Message)session.getAttribute(Message.ATTRIBUTE_KEY); if (message != null && !mav.getModelMap().containsKey(Message.ATTRIBUTE_KEY)) { mav.addObject(Message.ATTRIBUTE_KEY, message); } boolean shouldRemove = true; if (mav.hasView() && mav.getView() instanceof RedirectView) { shouldRemove = false; } if (mav.getViewName() != null && mav.getViewName().startsWith("redirect:")) { shouldRemove = false; } if (shouldRemove) { session.removeAttribute(Message.ATTRIBUTE_KEY); } } }
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView mav) { HttpSession session = request.getSession(); if (session != null) { Message message = (Message)session.getAttribute(Message.ATTRIBUTE_KEY); if (message != null && !mav.getModelMap().containsKey(Message.ATTRIBUTE_KEY)) { mav.addObject(Message.ATTRIBUTE_KEY, message); } boolean shouldRemove = true; if (mav.hasView() && mav.getView() instanceof RedirectView) { shouldRemove = false; } if (mav.getViewName() != null && mav.getViewName().startsWith("redirect:")) { shouldRemove = false; } if (shouldRemove) { session.removeAttribute(Message.ATTRIBUTE_KEY); } } }
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView mav) { HttpSession session = request.getSession(); if (session != null) { Message message = (Message)session.getAttribute(Message.ATTRIBUTE_KEY); if (message != null && !mav.getModelMap().containsKey(Message.ATTRIBUTE_KEY)) { mav.addObject(Message.ATTRIBUTE_KEY, message); } boolean shouldRemove = true; if (mav.hasView() && mav.getView() instanceof RedirectView) { shouldRemove = false; } if (mav.getViewName() != null && mav.getViewName().startsWith("redirect:")) { shouldRemove = false; } if (shouldRemove) { session.removeAttribute(Message.ATTRIBUTE_KEY); } } }
if (model.containsKey(DUPLICATED_USERNAME_KEY)) { LOG.warn("The username already exists. Displaying error to the user"); model.addAttribute(SIGNED_UP_MESSAGE_KEY, "false"); if (model.containsKey(DUPLICATED_EMAIL_KEY)) { LOG.warn("The email already exists. Displaying error to the user"); model.addAttribute(SIGNED_UP_MESSAGE_KEY, "false");
/** * Default method for the edit mode. Will show the edit form. * * @param model model * @param request request * @return A view */ @RenderMapping public String edit(ModelMap model, RenderRequest request) { if (!model.containsKey("invitePreferencesListFormBean")) { InvitePreferencesListFormBean preferencesListFormBean = new InvitePreferencesListFormBean(); List<InvitePreferences> all = invitePreferencesService.findAll(); preferencesListFormBean.setInvitePreferencesList(all); model.addAttribute("invitePreferencesListFormBean", preferencesListFormBean); } String message = request.getParameter("message"); if (message != null) { model.addAttribute("message", message); } if (model.get("errors") != null) { model.addAttribute("org.springframework.validation.BindingResult.passwordFormBean", model.get("errors")); return "editPreferencesForm"; } return "editForm"; }