Package org.springframework.web.bind

Examples of org.springframework.web.bind.ServletRequestDataBinder


   * @see #getCommandName
   */
  protected ServletRequestDataBinder createBinder(HttpServletRequest request, ThrowawayController command)
      throws Exception {

    ServletRequestDataBinder binder = new ServletRequestDataBinder(command, getCommandName());
    initBinder(request, binder);
    return binder;
  }
View Full Code Here


   * @param command command object, that must be a JavaBean
   * @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());
        }
      }
    }
    binder.closeNoCatch();
  }
View Full Code Here

   * @throws Exception in case of invalid state or arguments
   * @see #bind
   * @see #initBinder
   */
  protected ServletRequestDataBinder createBinder(HttpServletRequest request, Object command) throws Exception {
    ServletRequestDataBinder binder = new ServletRequestDataBinder(command, getCommandName(command));
    initBinder(request, binder);
    return binder;
  }
View Full Code Here

   * @throws Exception in case of invalid state or arguments
   */
  protected final ServletRequestDataBinder bindAndValidate(HttpServletRequest request, Object command)
      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

   * @see #initBinder
   */
  protected ServletRequestDataBinder createBinder(HttpServletRequest request, Object command)
      throws Exception {

    ServletRequestDataBinder binder = new ServletRequestDataBinder(command, getCommandName());
    prepareBinder(binder);
    initBinder(request, binder);
    return binder;
  }
View Full Code Here

   * @see ServletRequestDataBinder#convertIfNecessary(Object, Class, MethodParameter)
   */
  protected ServletRequestDataBinder createBinder(
      HttpServletRequest request, Object target, String objectName) throws Exception {

    return new ServletRequestDataBinder(target, objectName);
  }
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

    assertEquals(transfer2, ((MockFileItem) file2.getFileItem()).writtenFile);

    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());
    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);
    assertTrue(((MockFileItem) file2.getFileItem()).deleted);

    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);
    binder.bind(request);
    assertTrue(mtb2.getField1().length() == 0);
  }
View Full Code Here

*/
public class BindTagTests extends AbstractTagTests {

  public void testBindTagWithoutErrors() throws JspException {
    PageContext pc = createPageContext();
    Errors errors = new ServletRequestDataBinder(new TestBean(), "tb").getBindingResult();
    pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors);
    BindTag tag = new BindTag();
    tag.setPageContext(pc);
    tag.setPath("tb");
    assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
View Full Code Here

    assertTrue("Correct errorMessagesAsString", "".equals(status.getErrorMessagesAsString(",")));
  }

  public void testBindTagWithGlobalErrors() throws JspException {
    PageContext pc = createPageContext();
    Errors errors = new ServletRequestDataBinder(new TestBean(), "tb").getBindingResult();
    errors.reject("code1", "message1");
    pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors);

    BindTag tag = new BindTag();
    tag.setPageContext(pc);
View Full Code Here

TOP

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

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.