@Override public Map<String, Object> getModel() { return this.bindingResult.getModel(); }
@Override public Map<String, Object> getModel() { return this.bindingResult.getModel(); }
@Override public Map<String, Object> getModel() { return this.bindingResult.getModel(); }
@Override public Map<String, Object> getModel() { return this.bindingResult.getModel(); }
/** * Close this DataBinder, which may result in throwing * a BindException if it encountered any errors. * @return the model Map, containing target object and Errors instance * @throws BindException if there were any errors in the bind operation * @see BindingResult#getModel() */ public Map<?, ?> close() throws BindException { if (getBindingResult().hasErrors()) { throw new BindException(getBindingResult()); } return getBindingResult().getModel(); }
/** * Close this DataBinder, which may result in throwing * a BindException if it encountered any errors. * @return the model Map, containing target object and Errors instance * @throws BindException if there were any errors in the bind operation * @see BindingResult#getModel() */ public Map<?, ?> close() throws BindException { if (getBindingResult().hasErrors()) { throw new BindException(getBindingResult()); } return getBindingResult().getModel(); }
Map<String, Object> bindingResultModel = bindingResult.getModel(); mavContainer.removeAttributes(bindingResultModel); mavContainer.addAllAttributes(bindingResultModel);
@Test(expected = IllegalStateException.class) public void bindingResultNotFound() throws Exception { ModelAndViewContainer mavContainer = new ModelAndViewContainer(); mavContainer.addAllAttributes(bindingResult.getModel()); mavContainer.addAttribute("ignore1", "value1"); resolver.resolveArgument(paramErrors, mavContainer, webRequest, null); }
@Test public void bindingNoErrors() throws Exception { FieldAccessBean rod = new FieldAccessBean(); DataBinder binder = new DataBinder(rod, "person"); assertTrue(binder.isIgnoreUnknownFields()); binder.initDirectFieldAccess(); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.addPropertyValue(new PropertyValue("name", "Rod")); pvs.addPropertyValue(new PropertyValue("age", new Integer(32))); pvs.addPropertyValue(new PropertyValue("nonExisting", "someValue")); binder.bind(pvs); binder.close(); assertTrue("changed name correctly", rod.getName().equals("Rod")); assertTrue("changed age correctly", rod.getAge() == 32); Map<?, ?> m = binder.getBindingResult().getModel(); assertTrue("There is one element in map", m.size() == 2); FieldAccessBean tb = (FieldAccessBean) m.get("person"); assertTrue("Same object", tb.equals(rod)); }
Map<String, Object> bindingResultModel = bindingResult.getModel(); mavContainer.removeAttributes(bindingResultModel); mavContainer.addAllAttributes(bindingResultModel);
@Test public void bindingResult() throws Exception { ModelAndViewContainer mavContainer = new ModelAndViewContainer(); mavContainer.addAttribute("ignore1", "value1"); mavContainer.addAttribute("ignore2", "value2"); mavContainer.addAttribute("ignore3", "value3"); mavContainer.addAttribute("ignore4", "value4"); mavContainer.addAttribute("ignore5", "value5"); mavContainer.addAllAttributes(bindingResult.getModel()); Object actual = resolver.resolveArgument(paramErrors, mavContainer, webRequest, null); assertSame(actual, bindingResult); }
@Test public void testBindingWithAllowedFieldsUsingAsterisks() throws BindException { TestBean rod = new TestBean(); DataBinder binder = new DataBinder(rod, "person"); binder.setAllowedFields("nam*", "*ouchy"); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.add("name", "Rod"); pvs.add("touchy", "Rod"); pvs.add("age", "32x"); binder.bind(pvs); binder.close(); assertTrue("changed name correctly", "Rod".equals(rod.getName())); assertTrue("changed touchy correctly", "Rod".equals(rod.getTouchy())); assertTrue("did not change age", rod.getAge() == 0); String[] disallowedFields = binder.getBindingResult().getSuppressedFields(); assertEquals(1, disallowedFields.length); assertEquals("age", disallowedFields[0]); Map<?,?> m = binder.getBindingResult().getModel(); assertTrue("There is one element in map", m.size() == 2); TestBean tb = (TestBean) m.get("person"); assertTrue("Same object", tb.equals(rod)); }
Map<?, ?> map = binder.getBindingResult().getModel();
Map<?, ?> model = binder.getBindingResult().getModel();
@Test public void testBindingNoErrors() throws BindException { TestBean rod = new TestBean(); DataBinder binder = new DataBinder(rod, "person"); assertTrue(binder.isIgnoreUnknownFields()); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.add("name", "Rod"); pvs.add("age", "032"); pvs.add("nonExisting", "someValue"); binder.bind(pvs); binder.close(); assertTrue("changed name correctly", rod.getName().equals("Rod")); assertTrue("changed age correctly", rod.getAge() == 32); Map<?, ?> map = binder.getBindingResult().getModel(); assertTrue("There is one element in map", map.size() == 2); TestBean tb = (TestBean) map.get("person"); assertTrue("Same object", tb.equals(rod)); BindingResult other = new BeanPropertyBindingResult(rod, "person"); assertEquals(other, binder.getBindingResult()); assertEquals(binder.getBindingResult(), other); BindException ex = new BindException(other); assertEquals(ex, other); assertEquals(other, ex); assertEquals(ex, binder.getBindingResult()); assertEquals(binder.getBindingResult(), ex); other.reject("xxx"); assertTrue(!other.equals(binder.getBindingResult())); }
Map<?, ?> map = binder.getBindingResult().getModel();
Map<?, ?> model = binder.getBindingResult().getModel();
@Override public Map<String, Object> getModel() { return this.bindingResult.getModel(); }
/** * Close this DataBinder, which may result in throwing * a BindException if it encountered any errors. * @return the model Map, containing target object and Errors instance * @throws BindException if there were any errors in the bind operation * @see BindingResult#getModel() */ public Map<?, ?> close() throws BindException { if (getBindingResult().hasErrors()) { throw new BindException(getBindingResult()); } return getBindingResult().getModel(); }
private Object bindData(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { String name = ModelFactory.getNameForParameter(parameter); Object arg = BeanUtils.instantiateClass(parameter.getParameterType()); WebDataBinder binder = binderFactory.createBinder(webRequest, arg, name); binder.registerCustomEditor(byte[].class, this.byteArrayBase64PropertyEditor); ServletRequest servletRequest = webRequest.getNativeRequest(ServletRequest.class); ((ServletRequestDataBinder) binder).bind(servletRequest); Map<String, Object> bindingResultModel = binder.getBindingResult().getModel(); mavContainer.removeAttributes(bindingResultModel); mavContainer.addAllAttributes(bindingResultModel); return arg; }