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;
}
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());
}
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));
}
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"));
}
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);
}
Aggregations