Package br.com.caelum.vraptor.validator

Examples of br.com.caelum.vraptor.validator.ValidationMessage


  private void setProperty(OgnlContext context, String key, String[] values, List<Message> errors) {
    try {
      logger.debug("Applying {} with {}",key, values);
      Ognl.setValue(key, context, context.getRoot(), values.length == 1 ? values[0] : values);
    } catch (ConversionError ex) {
      errors.add(new ValidationMessage(ex.getMessage(), key));
    } catch (MethodFailedException e) { // setter threw an exception

      Throwable cause = e.getCause();
      if (cause.getClass().isAnnotationPresent(ValidationException.class)) {
        errors.add(new ValidationMessage(cause.getLocalizedMessage(), key));
      } else {
        throw new InvalidParameterException("unable to parse expression '" + key + "'", e);
      }

    } catch (NoSuchPropertyException ex) {
View Full Code Here


    for (ConstraintViolation<Object> violation : violations) {
      // interpolate the message
      final Context ctx = new Context(violation.getConstraintDescriptor(), violation.getInvalidValue());
      String msg = interpolator.interpolate(violation.getMessageTemplate(), ctx, locale);

      messages.add(new ValidationMessage(msg, violation.getPropertyPath().toString()));
      logger.debug("added message {} to validation of bean {}", msg, violation.getRootBean());
    }

    return messages;
  }
View Full Code Here

  public void adiciona(Espetaculo espetaculo) {
    // aqui eh onde fazemos as varias validacoes
    // se nao tiver nome, avisa o usuario
    // se nao tiver descricao, avisa o usuario
    if (Strings.isNullOrEmpty(espetaculo.getNome())) {
      validator.add(new ValidationMessage("Nome do espetáculo não pode estar em branco", ""));
    }
    if (Strings.isNullOrEmpty(espetaculo.getDescricao())) {
      validator.add(new ValidationMessage("Descrição do espetáculo não pode estar em branco", ""));
    }
    validator.onErrorRedirectTo(this).lista();

    agenda.cadastra(espetaculo);
    result.redirectTo(this).lista();
View Full Code Here

      result.notFound();
      return;
    }

    if (quantidade < 1) {
      validator.add(new ValidationMessage("Você deve escolher um lugar ou mais", ""));
    }

    if (!sessao.podeReservar(quantidade)) {
      validator.add(new ValidationMessage("Não existem ingressos disponíveis", ""));
    }

    // em caso de erro, redireciona para a lista de sessao
    validator.onErrorRedirectTo(this).sessao(sessao.getId());
View Full Code Here

  }

  private Espetaculo carregaEspetaculo(Long espetaculoId) {
    Espetaculo espetaculo = agenda.espetaculo(espetaculoId);
    if (espetaculo == null) {
      validator.add(new ValidationMessage("", ""));
    }
    validator.onErrorUse(status()).notFound();
    return espetaculo;
  }
View Full Code Here

      return null;
    }
  }
  private void handleException(Target<?> target, Throwable e) {
    if (e.getClass().isAnnotationPresent(ValidationException.class)) {
      errors.add(new ValidationMessage(e.getLocalizedMessage(), target.getName()));
    } else if (e.getCause() == null) {
      throw new InvalidParameterException("Exception when trying to instantiate " + target, e);
    } else {
      handleException(target, e.getCause());
    }
View Full Code Here

    public Object instantiate(Target<?> target, Parameters parameters) {
      try {
        Parameter parameter = parameters.namedAfter(target);
        return converterForTarget(target).convert(parameter.getValue(), target.getClassType(), localization.getBundle());
      } catch (ConversionError ex) {
        errors.add(new ValidationMessage(ex.getMessage(), target.getName()));
      } catch (IllegalStateException e) {
        return setPropertiesAfterConversions(target, parameters);
      }
      return null;
    }
View Full Code Here

    if (requestNames.containsKey(param.name)) {
      String[] values = requestNames.get(param.name);
      try {
        return createSimpleParameter(param, values, bundle);
      } catch(ConversionError ex) {
        errors.add(new ValidationMessage(ex.getMessage(), param.name));
        return null;
      }
    }

    try {
View Full Code Here

  private void setProperty(String name, String key, String[] values, List<Message> errors) {
    try {
      logger.debug("Applying {} with {}",key, values);
      ognl.setValue(name, key, values);
    } catch (ConversionError ex) {
      errors.add(new ValidationMessage(ex.getMessage(), key));
    }
  }
View Full Code Here

TOP

Related Classes of br.com.caelum.vraptor.validator.ValidationMessage

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.