Package org.apache.wicket.validation

Examples of org.apache.wicket.validation.ValidationError


            @Override
            public void validate(final IValidatable<ObjectAdapter> validatable) {
                final ObjectAdapter proposedAdapter = validatable.getValue();
                final String reasonIfAny = scalarModel.validate(proposedAdapter);
                if (reasonIfAny != null) {
                    final ValidationError error = new ValidationError();
                    error.setMessage(reasonIfAny);
                    validatable.error(error);
                }
            }
        });
    }
View Full Code Here


    {
      throw new IllegalArgumentException("Argument [[resourceKey]] cannot be null");
    }


    ValidationError error = new ValidationError().addKey(resourceKey);
    final String defaultKey = getClass().getSimpleName();
    if (!resourceKey.equals(defaultKey))
    {
      error.addKey(defaultKey);
    }

    error.setVariables(vars);
    fc.error(error);
  }
View Full Code Here

      {
        convertedInput = convertValue(getInputAsArray());
      }
      catch (ConversionException e)
      {
        ValidationError error = new ValidationError();
        if (e.getResourceKey() != null)
        {
          error.addKey(e.getResourceKey());
        }
        if (e.getTargetType() != null)
        {
          error.addKey("ConversionError." + e.getTargetType().getSimpleName());
        }
        error.addKey("ConversionError");
        reportValidationError(e, error);
      }
    }
    else
    {
      final IConverter<T> converter = getConverter(getType());

      try
      {
        convertedInput = converter.convertToObject(getInput(), getLocale());
      }
      catch (ConversionException e)
      {
        ValidationError error = new ValidationError();
        if (e.getResourceKey() != null)
        {
          error.addKey(e.getResourceKey());
        }
        String simpleName = getType().getSimpleName();
        error.addKey("IConverter." + simpleName);
        error.addKey("IConverter");
        error.setVariable("type", simpleName);
        reportValidationError(e, error);
      }
    }
  }
View Full Code Here

  /**
   * Reports required error against this component
   */
  private void reportRequiredError()
  {
    error(new ValidationError().addKey("Required"));
  }
View Full Code Here

  public void validate(IValidatable<String> validatable)
  {
    String email = validatable.getValue().toString();
    if (email.length() != email.trim().length())
    {
      validatable.error(decorate(new ValidationError(this), validatable));
    }
    else if (!PATTERN.matcher(validatable.getValue()).matches())
    {
      validatable.error(decorate(new ValidationError(this), validatable));
    }
  }
View Full Code Here

   *            the original cause
   * @return {@link ValidationError}
   */
  protected ValidationError newValidationError(ConversionException cause)
  {
    ValidationError error = new ValidationError(cause.getMessage());

    if (cause.getResourceKey() != null)
    {
      error.addKey(cause.getResourceKey());
    }

    if (typeName == null)
    {
      if (cause.getTargetType() != null)
      {
        error.addKey("ConversionError." + Classes.simpleName(cause.getTargetType()));
      }
      error.addKey("ConversionError");
    }
    else
    {
      String simpleName = Classes.simpleName(getType());
      error.addKey("IConverter." + simpleName);
      error.addKey("IConverter");
      error.setVariable("type", simpleName);
    }

    final Locale locale = cause.getLocale();
    if (locale != null)
    {
      error.setVariable("locale", locale);
    }

    error.setVariable("exception", cause);

    Format format = cause.getFormat();
    if (format instanceof SimpleDateFormat)
    {
      error.setVariable("format", ((SimpleDateFormat)format).toLocalizedPattern());
    }

    Map<String, Object> variables = cause.getVariables();
    if (variables != null)
    {
      error.getVariables().putAll(variables);
    }

    return error;
  }
View Full Code Here

  /**
   * Reports required error against this component
   */
  protected void reportRequiredError()
  {
    error(new ValidationError().addKey("Required"));
  }
View Full Code Here

  public void validate(IValidatable<String> validatable)
  {
    // Check value against pattern
    if (pattern.matcher(validatable.getValue()).matches() == reverse)
    {
      ValidationError error = new ValidationError(this);
      error.setVariable("pattern", pattern.pattern());
      validatable.error(decorate(error, validatable));
    }
  }
View Full Code Here

  public void validate(IValidatable<String> validatable)
  {
    String url = validatable.getValue();
    if (!isValid(url))
    {
      validatable.error(decorate(new ValidationError(this), validatable));
    }
  }
View Full Code Here

  {
    error = super.decorate(error, validatable);

    if (error instanceof ValidationError)
    {
      ValidationError ve = (ValidationError) error;
      ve.setVariable("inputdate", validatable.getValue());

      // format variables if format has been specified
      if (format != null)
      {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        if (getMinimum() != null)
        {
          ve.setVariable("minimum", sdf.format(getMinimum()));
        }
        if (getMaximum() != null)
        {
          ve.setVariable("maximum", sdf.format(getMaximum()));
        }
        ve.setVariable("inputdate", sdf.format(validatable.getValue()));
      }
    }

    return error;
  }
View Full Code Here

TOP

Related Classes of org.apache.wicket.validation.ValidationError

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.