Package org.apache.commons.validator

Examples of org.apache.commons.validator.Validator


        ActionErrors errors = new ActionErrors()

       

  Validator validator = StrutsValidatorUtil.initValidator(mapping.getAttribute(),

                                                          this,

                                                          application, request,

                                                          errors, page);

 

  try {

     validator.validate();

        } catch (ValidatorException e) {

     log.error(e.getMessage(), e);
View Full Code Here


                                 HttpServletRequest request) {

        ServletContext application = getServlet().getServletContext();
        ActionErrors errors = new ActionErrors()
       
  Validator validator = StrutsValidatorUtil.initValidator(mapping.getPath(),
                                                          this,
                                                          application, request,
                                                          errors, page);
 
  try {
     validator.validate();
        } catch (ValidatorException e) {
     log.error(e.getMessage(), e);
  }

        return errors;
View Full Code Here

        ActionErrors errors = new ActionErrors()

       

  Validator validator = StrutsValidatorUtil.initValidator(mapping.getAttribute(),

                                                          this,

                                                          application, request,

                                                          errors, page);

 

  try {

     validator.validate();

        } catch (ValidatorException e) {

     log.error(e.getMessage(), e);
View Full Code Here

                                 HttpServletRequest request) {

        ServletContext application = getServlet().getServletContext();
        ActionErrors errors = new ActionErrors()
       
  Validator validator = StrutsValidatorUtil.initValidator(mapping.getPath(),
                                                          this,
                                                          application, request,
                                                          errors, page);
 
  try {
     validator.validate();
        } catch (ValidatorException e) {
     log.error(e.getMessage(), e);
  }

        return errors;
View Full Code Here

        ActionErrors errors = new ActionErrors()

       

  Validator validator = StrutsValidatorUtil.initValidator(mapping.getAttribute(),

                                                          this,

                                                          application, request,

                                                          errors, page);

 

  try {

     validator.validate();

        } catch (ValidatorException e) {

     log.error(e.getMessage(), e);
View Full Code Here

                                         ActionErrors errors, int page) {

      ValidatorResources resources = StrutsValidatorUtil.getValidatorResources(application);
      Locale locale = StrutsValidatorUtil.getLocale(request);
     
      Validator validator = new Validator(resources, key);
      validator.setUseContextClassLoader(true);
     
      validator.setPage(page);
     
      validator.addResource(SERVLET_CONTEXT_KEY, application);
      validator.addResource(HTTP_SERVLET_REQUEST_KEY, request);
      validator.addResource(Validator.LOCALE_KEY, locale);
      validator.addResource(ACTION_ERRORS_KEY, errors);
      validator.addResource(Validator.BEAN_KEY, bean);
      
      return validator;     
   }
View Full Code Here

   * @param dataBean
   *            校验数据
   * */
  public static <T> Errors validateForm(String formName, T dataBean) {
    Errors errors = new Errors();
    Validator validator = factory.getValidator(formName, dataBean, errors);
    try {
      validator.validate();
    } catch (ValidatorException e) {
      LOGGER.info("校验数据发生异常,校验的FormName为" + formName, e);
      errors.addError("SYSERROR", "系统发生异常,请重新尝试!");
    }
    return errors;
View Full Code Here

      throw new FatalBeanException("Unable to parse validation configuration XML", e);
    }
  }

  public Validator getValidator(String beanName, Object bean, Errors errors) {
    Validator validator = new Validator(validatorResources, beanName);
    validator.setParameter(ERRORS_KEY, errors);
    validator.setParameter(Validator.BEAN_PARAM, bean);
    return validator;
  }
View Full Code Here

        // Create a test bean to validate against.
        ValidateBean bean = new ValidateBean();
       
        // Create a validator with the ValidateBean actions for the bean
        // we're interested in.
        Validator validator = new Validator(resources, "ValidateBean");
       
        // Tell the validator which bean to validate against.
        validator.setParameter(Validator.BEAN_PARAM, bean);
       
        ValidatorResults results = null;
       
        // Run the validation actions against the bean.  Since all of the properties
        // are null, we expect them all to error out except for street2, which has
        // no validations (it's an optional property)
       
        results = validator.validate();
        printResults(bean, results, resources);
       
        // Now set all the required properties, but make the age a non-integer.
        // You'll notice that age will pass the required test, but fail the int
        // test.
        bean.setLastName("Tester");
        bean.setFirstName("John");
        bean.setStreet1("1 Test Street");
        bean.setCity("Testville");
        bean.setState("TE");
        bean.setPostalCode("12345");
        bean.setAge("Too Old");
        results = validator.validate();
        printResults(bean, results, resources);
       
        // Now only report failed fields
        validator.setOnlyReturnErrors(true);
        results = validator.validate();
        printResults(bean, results, resources);
       
        // Now everything should pass.
        validator.setOnlyReturnErrors(false);
        bean.setAge("123");
        results = validator.validate();
        printResults(bean, results, resources);
    }
View Full Code Here

                                 HttpServletRequest request) {

        ServletContext application = getServlet().getServletContext();
        ActionErrors errors = new ActionErrors();

    Validator validator = StrutsValidatorUtil.initValidator(mapping.getPath(),
                                                            this,
                                                            application, request,
                                                            errors, page);

    try {
       validatorResults = validator.validate();
        } catch (ValidatorException e) {
       log.error(e.getMessage(), e);
    }

        return errors;
View Full Code Here

TOP

Related Classes of org.apache.commons.validator.Validator

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.