Spring Framework ModelMap - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework ModelMap class.

This code example shows how to use the following methods:size, get, keySet
	@Override 
	public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
			NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
 
		ModelMap model = mavContainer.getModel();
		if (model.size() > 0) {
			int lastIndex = model.size()-1;
			String lastKey = new ArrayList<String>(model.keySet()).get(lastIndex);
			if (lastKey.startsWith(BindingResult.MODEL_KEY_PREFIX)) {
				return model.get(lastKey);
			} 
		} 
 
		throw new IllegalStateException(
				"An Errors/BindingResult argument is expected to be declared immediately after the model attribute, " + 
				"the @RequestBody or the @RequestPart arguments to which they apply: " + parameter.getMethod());
	} 
 
} 
8
CodeRank
This code example shows how to use the following methods:get, put
        controller.setClientDetailsService(clientDetailsService);
        controller.setApprovalStore(Mockito.mock(ApprovalStore.class));
        MockHttpServletRequest request = new MockHttpServletRequest();
        request.setScheme("https");
        request.addHeader("Host", "foo");
        ModelMap model = new ModelMap();
        model.put("authorizationRequest", new AuthorizationRequest("client", null));
        Authentication auth = UaaAuthenticationTestFactory.getAuthentication("foo@bar.com", "Foo Bar", "foo@bar.com");
        controller.confirm(model, request, auth, new SimpleSessionStatus());
        Map<String, Object> options = (Map<String, Object>) ((Map<String, Object>) model.get("options")).get("confirm");
        assertEquals("https://foo/oauth/authorize", options.get("location"));
        assertEquals("/oauth/authorize", options.get("path"));
    } 
 
} 
7
CodeRank
This code example shows how to use the following methods:
		assertEquals(url + "/value1/v1/value2?key3=value3", this.response.getRedirectedUrl()); 
	} 
 
	@Test(expected=IllegalArgumentException.class) 
	public void uriTemplateNullValue() throws Exception { 
		new RedirectView("/{foo}").renderMergedOutputModel(new ModelMap(), this.request, this.response); 
	} 
 
	@Test 
	public void emptyRedirectString() throws Exception { 
		Map<String, Object> model = new HashMap<String, Object>(); 
 
		RedirectView redirectView = new RedirectView(""); 
		redirectView.renderMergedOutputModel(model, this.request, this.response); 
 
		assertEquals("", this.response.getRedirectedUrl()); 
	} 
 
	// SPR-9016 
 
7
CodeRank
This code example shows how to use the following methods:
		assertEquals(1, this.mavContainer.getModel().size());
	} 
 
	@Test
	public void getModelRedirectModel() { 
		ModelMap redirectModel = new ModelMap("name", "redirectValue");
		this.mavContainer.setRedirectModel(redirectModel);
		this.mavContainer.addAttribute("name", "value");
 
		assertEquals("Default model should be used if not in redirect scenario", 
				"value", this.mavContainer.getModel().get("name"));
 
		this.mavContainer.setRedirectModelScenario(true);
 
		assertEquals("Redirect model should be used in redirect scenario", 
				"redirectValue", this.mavContainer.getModel().get("name"));
	} 
 
	@Test
	public void getModelIgnoreDefaultModelOnRedirect() { 
7
CodeRank
This code example shows how to use the following methods:addAttribute
    @Autowired 
    ApprovalService approvalService;
 
    @RequestMapping(value="id-{id}/approve", method=RequestMethod.POST)
    public ModelMap approve(@PathVariable(value="id") Long id) throws Exception {
        ModelMap model = new ModelMap();
        Object result = approvalService.approve(id);
        if(result.toString().startsWith("Error")) {
            model.addAttribute("status", "error");
        } else { 
            model.addAttribute("status", "success");
        } 
        model.addAttribute("result", result);
        return model;
    } 
 
    @RequestMapping(value="id-{id}/reject", method=RequestMethod.POST)
    public ModelMap reject(@PathVariable(value="id") Long id) throws Exception {
        ModelMap model = new ModelMap();
        approvalService.reject(id);
6
CodeRank
This code example shows how to use the following methods:addAttribute, get
 
	// 直接调用方法需要把root参数保存至model中 
	@RequestMapping(value = "/file/v_list.do") 
	public String list(HttpServletRequest request, ModelMap model) {
		CmsSite site = CmsUtils.getSite(request);
		String root = (String) model.get("root");
		if (root == null) {
			root = RequestUtils.getQueryParam(request, "root");
		} 
		String valid=RequestUtils.getQueryParam(request, "valid");
		Boolean validB=null;
		if(StringUtils.isNotBlank(valid)){
			if(valid.equals("1")){
				validB=true;
			}else{ 
				validB=false;
			} 
		} 
		log.debug("list Resource root: {}", root);
		if (StringUtils.isBlank(root)) {

6
CodeRank
This code example shows how to use the following methods:
	} 
 
	@Test 
	public void handleMapReturnValue() throws Exception { 
		mavContainer.addAttribute("attr1", "value1"); 
		Map<String, Object> returnValue = new ModelMap("attr2", "value2"); 
 
		processor.handleReturnValue(returnValue , returnParamMap, mavContainer, webRequest); 
 
		assertEquals("value1", mavContainer.getModel().get("attr1")); 
		assertEquals("value2", mavContainer.getModel().get("attr2")); 
	} 
 
	@SuppressWarnings("unused") 
	private Map<String, Object> map(Map<String, Object> map) { 
		return null; 
	} 
 
} 
6
CodeRank
This code example shows how to use the following methods:
 * 
 * <p>This resolver must be listed ahead of 
 * {@link org.springframework.web.method.annotation.ModelMethodProcessor} and 
 * {@link org.springframework.web.method.annotation.MapMethodProcessor}, 
 * which support {@link Map} and {@link Model} arguments both of which are 
 * "super" types of {@code RedirectAttributes} and would also attempt to 
 * resolve a {@code RedirectAttributes} argument. 
 * 
 * @author Rossen Stoyanchev 
 * @since 3.1 
 */ 
public class RedirectAttributesMethodArgumentResolver implements HandlerMethodArgumentResolver {
 
	@Override 
	public boolean supportsParameter(MethodParameter parameter) {
		return RedirectAttributes.class.isAssignableFrom(parameter.getParameterType());
	} 
 
	@Override 
	public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
6
CodeRank
This code example shows how to use the following methods:addAttribute
 
	@RequestMapping("/common/v_image_area_select.do") 
	public String imageAreaSelect(String uploadBase, String imgSrcPath,
			Integer zoomWidth, Integer zoomHeight, Integer uploadNum,
			HttpServletRequest request, ModelMap model) {
		model.addAttribute("uploadBase", uploadBase);
		model.addAttribute("imgSrcPath", imgSrcPath);
		model.addAttribute("zoomWidth", zoomWidth);
		model.addAttribute("zoomHeight", zoomHeight);
		model.addAttribute("uploadNum", uploadNum);
		return IMAGE_SELECT_RESULT;
	} 
 
	@RequestMapping("/common/o_image_cut.do") 
	public String imageCut(String imgSrcPath, Integer imgTop, Integer imgLeft,
			Integer imgWidth, Integer imgHeight, Integer reMinWidth,
			Integer reMinHeight, Float imgScale, Integer uploadNum,
			HttpServletRequest request, ModelMap model) {
		CmsSite site = CmsUtils.getSite(request);
		try { 
6
CodeRank
This code example shows how to use the following methods:
		UserFormController controller = new UserFormController(); 
		WebRequest request = new ServletWebRequest(new MockHttpServletRequest()); 
		User user = controller.formBackingObject(request, null); 
		user.addName(new PersonName("This", "is", "Test")); 
		user.getPerson().setGender("F"); 
		controller.handleSubmission(request, new MockHttpSession(), new ModelMap(), "Save User", "pass123", "pass123", null, 
		    null, null, new String[0], "true", user, new BindException(user, "user")); 
	} 
	 
} 
6
CodeRank
See Code Examples for Spring Framework ModelMap Methods: