Package org.springframework.web.bind

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


   * @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 (int i = 0; i < this.validators.length; i++) {
        if (this.validators[i].supports(command.getClass())) {
          ValidationUtils.invokeValidator(this.validators[i], command, binder.getBindingResult());
        }
View Full Code Here


      throws Exception {

    ServletRequestDataBinder binder = createBinder(request, command);
    BindException errors = new BindException(binder.getBindingResult());
    if (!suppressBinding(request)) {
      binder.bind(request);
      onBind(request, command, errors);
      if (this.validators != null && isValidateOnBinding() && !suppressValidation(request, command, errors)) {
        for (int i = 0; i < this.validators.length; i++) {
          ValidationUtils.invokeValidator(this.validators[i], command, errors);
        }
View Full Code Here

    @Override
    protected void doBind(NativeWebRequest webRequest, WebDataBinder binder, boolean failOnErrors)
        throws Exception {

      ServletRequestDataBinder servletBinder = (ServletRequestDataBinder) binder;
      servletBinder.bind((ServletRequest) webRequest.getNativeRequest());
      if (failOnErrors) {
        servletBinder.closeNoCatch();
      }
    }
View Full Code Here

    MultipartTestBean1 mtb1 = new MultipartTestBean1();
    assertEquals(null, mtb1.getField1());
    assertEquals(null, mtb1.getField2());
    ServletRequestDataBinder binder = new ServletRequestDataBinder(mtb1, "mybean");
    binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor());
    binder.bind(request);
    assertEquals(file1, mtb1.getField1());
    assertEquals(new String(file2.getBytes()), new String(mtb1.getField2()));

    MultipartTestBean2 mtb2 = new MultipartTestBean2();
    assertEquals(null, mtb2.getField1());
View Full Code Here

    assertEquals(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(file1.getBytes()), mtb2.getField1());
    assertEquals(new String(file2.getBytes(), "UTF-16"), mtb2.getField2());

    resolver.cleanupMultipart(request);
    assertTrue(((MockFileItem) file1.getFileItem()).deleted);
View Full Code Here

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

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

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

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

  public void testWithServletContextAndFilter() throws Exception {
    StaticWebApplicationContext wac = new StaticWebApplicationContext();
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

        // 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

            throws Exception {

        ServletRequestDataBinder binder = createBinder(request, command);
        BindException errors = new BindException(binder.getBindingResult());
        if (!suppressBinding(request)) {
            binder.bind(request);
            onBind(request, command, errors);
            if (this.validators != null && isValidateOnBinding() && !suppressValidation(request, command, errors)) {
                for (int i = 0; i < this.validators.length; i++) {
                    ValidationUtils.invokeValidator(this.validators[i], command, 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.