Package org.springframework.validation

Examples of org.springframework.validation.DataBinder


  }

  public void testBindTagWithIndexedPropertiesAndCustomEditor() throws JspException {
    PageContext pc = createPageContext();
    IndexedTestBean tb = new IndexedTestBean();
    DataBinder binder = new ServletRequestDataBinder(tb, "tb");
    binder.registerCustomEditor(TestBean.class, null, new PropertyEditorSupport() {
      public String getAsText() {
        return "something";
      }
    });
    Errors errors = binder.getBindingResult();
    errors.rejectValue("array[0]", "code1", "message1");
    errors.rejectValue("array[0]", "code2", "message2");
    pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors);

    BindTag tag = new BindTag();
View Full Code Here


  public Event bindAndValidate(RequestContext context) throws Exception {
    if (logger.isDebugEnabled()) {
      logger.debug("Executing bind");
    }
    Object formObject = getFormObject(context);
    DataBinder binder = createBinder(context, formObject);
    doBind(context, binder);
    if (getValidator() != null && validationEnabled(context)) {
      if (logger.isDebugEnabled()) {
        logger.debug("Executing validation");
      }
      doValidate(context, formObject, binder.getBindingResult());
    } else {
      if (logger.isDebugEnabled()) {
        if (getValidator() == null) {
          logger.debug("No validator is configured, no validation will occur after binding");
        } else {
          logger.debug("Validation was disabled for this bindAndValidate request");
        }
      }
    }
    putFormErrors(context, binder.getBindingResult());
    return binder.getBindingResult().hasErrors() ? error() : success();
  }
View Full Code Here

  public Event bind(RequestContext context) throws Exception {
    if (logger.isDebugEnabled()) {
      logger.debug("Executing bind");
    }
    Object formObject = getFormObject(context);
    DataBinder binder = createBinder(context, formObject);
    doBind(context, binder);
    putFormErrors(context, binder.getBindingResult());
    return binder.getBindingResult().hasErrors() ? error() : success();
  }
View Full Code Here

   * @see WebDataBinder
   * @see #initBinder(RequestContext, DataBinder)
   * @see #setMessageCodesResolver(MessageCodesResolver)
   */
  protected DataBinder createBinder(RequestContext context, Object formObject) throws Exception {
    DataBinder binder = new WebDataBinder(formObject, getFormObjectName());
    if (getMessageCodesResolver() != null) {
      binder.setMessageCodesResolver(getMessageCodesResolver());
    }
    initBinder(context, binder);
    registerPropertyEditors(context, binder);
    return binder;
  }
View Full Code Here

      Locale locale, School school, Provider provider) throws Exception {
    this.entities = new ArrayList<Course>();
    Map<Course , List<FieldError>> executions = new HashMap<Course , List<FieldError>>();
    for(Course course : courses) {
      course.setRegulated(provider.getRegulated());
      DataBinder dataBinder = new DataBinder(course);
      dataBinder.setValidator(validator);
      dataBinder.validate();
      executions.put(course, dataBinder.getBindingResult().getFieldErrors());
      if(!dataBinder.getBindingResult().hasErrors()) {
        this.selectiveCourseStore(course, locale);
      }
    }
    this.flush(locale);
   
View Full Code Here

  @Override
  public Map<School, List<FieldError>> store(Collection<School> objs,
      Locale locale, Provider provider) throws Exception {
    Map<School , List<FieldError>> executions = new HashMap<School , List<FieldError>>();
    for(School school : objs) {
      DataBinder dataBinder = new DataBinder(school);
      dataBinder.setValidator(validator);
      dataBinder.validate();
      executions.put(school, dataBinder.getBindingResult().getFieldErrors());
      if(!dataBinder.getBindingResult().hasErrors()) {
        this.selectiveSchoolStore(school, locale);
      }
    }
    this.flush(locale);
    return executions;
View Full Code Here

    @Override
    protected void populateOperation(Operation op, JoinPoint jp) {
        super.populateOperation(op, jp);

        DataBinder binder = extractDataBinderArg(jp);
        if (binder == null) {
            return;
        }

        String objectName = binder.getObjectName();
        op.label("Init Binder " + objectName)
                .put(OBJECT_NAME, objectName);

        Object target = binder.getTarget();
        if (target == null) {
            // Target object may be null according to WebDataBinder docs
            op.put(TARGET_TYPE, UNKNOWN_TARGET_TYPE);
        } else {
            op.put(TARGET_TYPE, target.getClass().getName());
        }

        fromArray(op.createList(ALLOWED_FIELDS_LIST), binder.getAllowedFields());
        fromArray(op.createList(DISALLOWED_FIELDS_LIST), binder.getDisallowedFields());
        fromArray(op.createList(REQUIRED_FIELDS_LIST), binder.getRequiredFields());
    }
View Full Code Here

  public Event bindAndValidate(RequestContext context) throws Exception {
    if (logger.isDebugEnabled()) {
      logger.debug("Executing bind");
    }
    Object formObject = getFormObject(context);
    DataBinder binder = createBinder(context, formObject);
    doBind(context, binder);
    if (getValidator() != null && validationEnabled(context)) {
      if (logger.isDebugEnabled()) {
        logger.debug("Executing validation");
      }
      doValidate(context, formObject, binder.getBindingResult());
    } else {
      if (logger.isDebugEnabled()) {
        if (getValidator() == null) {
          logger.debug("No validator is configured, no validation will occur after binding");
        } else {
          logger.debug("Validation was disabled for this bindAndValidate request");
        }
      }
    }
    putFormErrors(context, binder.getBindingResult());
    return binder.getBindingResult().hasErrors() ? error() : success();
  }
View Full Code Here

  public Event bind(RequestContext context) throws Exception {
    if (logger.isDebugEnabled()) {
      logger.debug("Executing bind");
    }
    Object formObject = getFormObject(context);
    DataBinder binder = createBinder(context, formObject);
    doBind(context, binder);
    putFormErrors(context, binder.getBindingResult());
    return binder.getBindingResult().hasErrors() ? error() : success();
  }
View Full Code Here

   * @see WebDataBinder
   * @see #initBinder(RequestContext, DataBinder)
   * @see #setMessageCodesResolver(MessageCodesResolver)
   */
  protected DataBinder createBinder(RequestContext context, Object formObject) throws Exception {
    DataBinder binder = new WebDataBinder(formObject, getFormObjectName());
    if (getMessageCodesResolver() != null) {
      binder.setMessageCodesResolver(getMessageCodesResolver());
    }
    initBinder(context, binder);
    registerPropertyEditors(context, binder);
    return binder;
  }
View Full Code Here

TOP

Related Classes of org.springframework.validation.DataBinder

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.