Package org.springframework.web.bind

Examples of org.springframework.web.bind.WebDataBinder


  public void createBinderTypeConversion() throws Exception {
    webRequest.getNativeRequest(MockHttpServletRequest.class).setParameter("requestParam", "22");
    argumentResolvers.addResolver(new RequestParamMethodArgumentResolver(null, false));

    WebDataBinderFactory factory = createBinderFactory("initBinderTypeConversion", WebDataBinder.class, int.class);
    WebDataBinder dataBinder = factory.createBinder(webRequest, null, "foo");

    assertNotNull(dataBinder.getDisallowedFields());
    assertEquals("requestParam-22", dataBinder.getDisallowedFields()[0]);
  }
View Full Code Here


  // SPR-10578

  @Test
  public void missingRequestParamEmptyValueConvertedToNull() throws Exception {

    WebDataBinder binder = new WebRequestDataBinder(null);
    binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));

    WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class);
    given(binderFactory.createBinder(webRequest, null, "stringNotAnnot")).willReturn(binder);

    this.request.addParameter("stringNotAnnot", "");
View Full Code Here

  }

  @Test
  public void missingRequestParamEmptyValueNotRequired() throws Exception {

    WebDataBinder binder = new WebRequestDataBinder(null);
    binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));

    WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class);
    given(binderFactory.createBinder(webRequest, null, "name")).willReturn(binder);

    this.request.addParameter("name", "");
View Full Code Here

    @Override
    public WebDataBinder createBinder(NativeWebRequest webRequest, Object target, String objectName) {
      LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
      validator.afterPropertiesSet();
      WebDataBinder dataBinder = new WebDataBinder(target, objectName);
      dataBinder.setValidator(validator);
      return dataBinder;
    }
View Full Code Here

  private final class ValidatingBinderFactory implements WebDataBinderFactory {
    @Override
    public WebDataBinder createBinder(NativeWebRequest webRequest, Object target, String objectName) throws Exception {
      LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
      validator.afterPropertiesSet();
      WebDataBinder dataBinder = new WebDataBinder(target, objectName);
      dataBinder.setValidator(validator);
      return dataBinder;
    }
View Full Code Here

    uriTemplateVars.put("name", "nameValue");
    uriTemplateVars.put("age", "25");
    request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars);

    TestBean target = new TestBean();
    WebDataBinder binder = new ExtendedServletRequestDataBinder(target, "");
    ((ServletRequestDataBinder) binder).bind(request);

    assertEquals("nameValue", target.getName());
    assertEquals(25, target.getAge());
  }
View Full Code Here

    uriTemplateVars.put("name", "nameValue");
    uriTemplateVars.put("age", "25");
    request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars);

    TestBean target = new TestBean();
    WebDataBinder binder = new ExtendedServletRequestDataBinder(target, "");
    ((ServletRequestDataBinder) binder).bind(request);

    assertEquals("nameValue", target.getName());
    assertEquals(35, target.getAge());
  }
View Full Code Here

  }

  @Test
  public void noUriTemplateVars() throws Exception {
    TestBean target = new TestBean();
    WebDataBinder binder = new ExtendedServletRequestDataBinder(target, "");
    ((ServletRequestDataBinder) binder).bind(request);

    assertEquals(null, target.getName());
    assertEquals(0, target.getAge());
  }
View Full Code Here

  private final class ValidatingBinderFactory implements WebDataBinderFactory {
    @Override
    public WebDataBinder createBinder(NativeWebRequest webRequest, Object target, String objectName) throws Exception {
      LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
      validator.afterPropertiesSet();
      WebDataBinder dataBinder = new WebDataBinder(target, objectName);
      dataBinder.setValidator(validator);
      return dataBinder;
    }
View Full Code Here

  private void getAttributeFromModel(String expectedAttributeName, MethodParameter param) throws Exception {
    Object target = new TestBean();
    mavContainer.addAttribute(expectedAttributeName, target);

    WebDataBinder dataBinder = new WebRequestDataBinder(target);
    WebDataBinderFactory factory = mock(WebDataBinderFactory.class);
    given(factory.createBinder(webRequest, target, expectedAttributeName)).willReturn(dataBinder);

    processor.resolveArgument(param, mavContainer, webRequest, factory);
    verify(factory).createBinder(webRequest, target, expectedAttributeName);
View Full Code Here

TOP

Related Classes of org.springframework.web.bind.WebDataBinder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.