Package org.springframework.web.bind

Examples of org.springframework.web.bind.ServletRequestDataBinder.bind()


    private BindingResult doBind(HttpServletRequest webRequest, Class<? extends RopRequest> requestType) {
        RopRequest bindObject = BeanUtils.instantiateClass(requestType);
        ServletRequestDataBinder dataBinder = new ServletRequestDataBinder(bindObject, "bindObject");
        dataBinder.setConversionService(getFormattingConversionService());
        dataBinder.setValidator(getValidator());
        dataBinder.bind(webRequest);
        dataBinder.validate();
        return dataBinder.getBindingResult();
    }

    private Validator getValidator() {
View Full Code Here


     * useful for POJOs which are configurable via request parameters such as
     * for query/view POJOs
     */
    protected Object bindRequestBean(Object bean, ServletRequest request) {
        ServletRequestDataBinder binder = new ServletRequestDataBinder(bean, null);
        binder.bind(request);
        return bean;
    }

}
View Full Code Here

   * @throws Exception in case of invalid state or arguments
   */
  protected void bind(HttpServletRequest request, Object command) throws Exception {
    logger.debug("Binding request parameters onto MultiActionController command");
    ServletRequestDataBinder binder = createBinder(request, command);
    binder.bind(request);
    if (this.validators != null) {
      for (Validator validator : this.validators) {
        if (validator.supports(command.getClass())) {
          ValidationUtils.invokeValidator(validator, command, binder.getBindingResult());
        }
View Full Code Here

   */
  @Override
  protected void bindRequestParameters(WebDataBinder binder, NativeWebRequest request) {
    ServletRequest servletRequest = request.getNativeRequest(ServletRequest.class);
    ServletRequestDataBinder servletBinder = (ServletRequestDataBinder) binder;
    servletBinder.bind(servletRequest);
  }

}
View Full Code Here

    }

    @Override
    protected void doBind(WebDataBinder binder, NativeWebRequest webRequest) throws Exception {
      ServletRequestDataBinder servletBinder = (ServletRequestDataBinder) binder;
      servletBinder.bind(webRequest.getNativeRequest(ServletRequest.class));
    }

    @Override
    protected HttpInputMessage createHttpInputMessage(NativeWebRequest webRequest) throws Exception {
      HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class);
View Full Code Here

    MultipartTestBean1 mtb1 = new MultipartTestBean1();
    assertArrayEquals(null, mtb1.getField1());
    assertEquals(null, mtb1.getField2());
    ServletRequestDataBinder binder = new ServletRequestDataBinder(mtb1, "mybean");
    binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor());
    binder.bind(request);
    List<MultipartFile> file1List = request.getFiles("field1");
    CommonsMultipartFile file1a = (CommonsMultipartFile) file1List.get(0);
    CommonsMultipartFile file1b = (CommonsMultipartFile) file1List.get(1);
    CommonsMultipartFile file2 = (CommonsMultipartFile) request.getFile("field2");
    assertEquals(file1a, mtb1.getField1()[0]);
View Full Code Here

    assertArrayEquals(null, mtb2.getField1());
    assertEquals(null, mtb2.getField2());
    binder = new ServletRequestDataBinder(mtb2, "mybean");
    binder.registerCustomEditor(String.class, "field1", new StringMultipartFileEditor());
    binder.registerCustomEditor(String.class, "field2", new StringMultipartFileEditor("UTF-16"));
    binder.bind(request);
    assertEquals(new String(file1a.getBytes()), mtb2.getField1()[0]);
    assertEquals(new String(file1b.getBytes()), mtb2.getField1()[1]);
    assertEquals(new String(file2.getBytes(), "UTF-16"), mtb2.getField2());

    resolver.cleanupMultipart(request);
View Full Code Here

    resolver.setEmpty(true);
    request = resolver.resolveMultipart(originalRequest);
    binder.setBindEmptyMultipartFiles(false);
    String firstBound = mtb2.getField2();
    binder.bind(request);
    assertTrue(mtb2.getField2().length() > 0);
    assertEquals(firstBound, mtb2.getField2());

    request = resolver.resolveMultipart(originalRequest);
    binder.setBindEmptyMultipartFiles(true);
View Full Code Here

    assertTrue(mtb2.getField2().length() > 0);
    assertEquals(firstBound, mtb2.getField2());

    request = resolver.resolveMultipart(originalRequest);
    binder.setBindEmptyMultipartFiles(true);
    binder.bind(request);
    assertTrue(mtb2.getField2().length() == 0);
  }

  @Test
  public void withServletContextAndFilter() throws Exception {
View Full Code Here

    // convenient error evaluation in views (on both first attempt and resubmit).
    ServletRequestDataBinder binder = createBinder(request, command);
    BindException errors = new BindException(binder.getBindingResult());
    if (isBindOnNewForm()) {
      logger.debug("Binding to new form");
      binder.bind(request);
      onBindOnNewForm(request, command, errors);
    }

    // Return BindException object that resulted from binding.
    return errors;
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.