Search in sources :

Example 1 with ModelMap

use of org.springframework.ui.ModelMap in project head by mifos.

the class ApprovalRESTController method updateMethodData.

@RequestMapping(value = "id-{id}/methodData", method = RequestMethod.POST)
public ModelMap updateMethodData(@PathVariable(value = "id") Long id, @RequestBody ApprovalMethod content) throws Exception {
    ModelMap model = new ModelMap();
    approvalService.updateMethodContent(id, content);
    model.addAttribute("status", "success");
    return model;
}
Also used : ModelMap(org.springframework.ui.ModelMap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ModelMap

use of org.springframework.ui.ModelMap in project spring-framework by spring-projects.

the class ErrorsMethodArgumentResolver method resolveArgument.

@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<>(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());
}
Also used : ModelMap(org.springframework.ui.ModelMap)

Example 3 with ModelMap

use of org.springframework.ui.ModelMap in project spring-framework by spring-projects.

the class ModelFactoryTests method updateModelWhenRedirecting.

// SPR-12542
@Test
public void updateModelWhenRedirecting() throws Exception {
    String attributeName = "sessionAttr";
    String attribute = "value";
    ModelAndViewContainer container = new ModelAndViewContainer();
    container.addAttribute(attributeName, attribute);
    String queryParam = "123";
    String queryParamName = "q";
    container.setRedirectModel(new ModelMap(queryParamName, queryParam));
    container.setRedirectModelScenario(true);
    WebDataBinder dataBinder = new WebDataBinder(attribute, attributeName);
    WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class);
    given(binderFactory.createBinder(this.webRequest, attribute, attributeName)).willReturn(dataBinder);
    ModelFactory modelFactory = new ModelFactory(null, binderFactory, this.attributeHandler);
    modelFactory.updateModel(this.webRequest, container);
    assertEquals(queryParam, container.getModel().get(queryParamName));
    assertEquals(1, container.getModel().size());
    assertEquals(attribute, this.attributeStore.retrieveAttribute(this.webRequest, attributeName));
}
Also used : WebDataBinder(org.springframework.web.bind.WebDataBinder) ModelAndViewContainer(org.springframework.web.method.support.ModelAndViewContainer) ModelMap(org.springframework.ui.ModelMap) WebDataBinderFactory(org.springframework.web.bind.support.WebDataBinderFactory) Test(org.junit.Test)

Example 4 with ModelMap

use of org.springframework.ui.ModelMap in project spring-framework by spring-projects.

the class ModelAndViewContainerTests method redirectScenarioWithRedirectModel.

@Test
public void redirectScenarioWithRedirectModel() {
    this.mavContainer.addAttribute("name1", "value1");
    this.mavContainer.setRedirectModel(new ModelMap("name2", "value2"));
    this.mavContainer.setRedirectModelScenario(true);
    assertEquals(1, this.mavContainer.getModel().size());
    assertEquals("value2", this.mavContainer.getModel().get("name2"));
}
Also used : ModelMap(org.springframework.ui.ModelMap) Test(org.junit.Test)

Example 5 with ModelMap

use of org.springframework.ui.ModelMap in project spring-framework by spring-projects.

the class SessionAttributesHandlerTests method storeAttributes.

@Test
public void storeAttributes() throws Exception {
    ModelMap model = new ModelMap();
    model.put("attr1", "value1");
    model.put("attr2", "value2");
    model.put("attr3", new TestBean());
    sessionAttributesHandler.storeAttributes(request, model);
    assertEquals("value1", sessionAttributeStore.retrieveAttribute(request, "attr1"));
    assertEquals("value2", sessionAttributeStore.retrieveAttribute(request, "attr2"));
    assertTrue(sessionAttributeStore.retrieveAttribute(request, "attr3") instanceof TestBean);
}
Also used : TestBean(org.springframework.tests.sample.beans.TestBean) ModelMap(org.springframework.ui.ModelMap) Test(org.junit.Test)

Aggregations

ModelMap (org.springframework.ui.ModelMap)48 Test (org.junit.Test)23 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)18 ModelAndView (org.springframework.web.servlet.ModelAndView)11 RedirectAttributesModelMap (org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap)9 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)5 Map (java.util.Map)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 IOException (java.io.IOException)3 Date (java.util.Date)3 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)3 HttpSessionRequiredException (org.springframework.web.HttpSessionRequiredException)3 RedirectAttributes (org.springframework.web.servlet.mvc.support.RedirectAttributes)3 NimbusClient (backtype.storm.utils.NimbusClient)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ParseException (java.text.ParseException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 HttpSession (javax.servlet.http.HttpSession)2