Package br.com.caelum.vraptor.validator

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


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


      logger.debug("there are {} constraint violations at method {}.", violations.size(), method);

      for (ConstraintViolation<Object> v : violations) {
        String category = extractCategory(methodInfo.getValuedParameters(), v);
        String msg = extractInternacionalizedMessage(v);
        validator.add(new SimpleMessage(category, msg));
        logger.debug("added message {}={} for contraint violation", category, msg);
      }
    }
  }
View Full Code Here

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

  private <T> Answer<T> addErrorsToListAndReturn(final T value, final String... messages) {
    return new Answer<T>() {
      @Override
      public T answer(InvocationOnMock invocation) throws Throwable {
        for (String message : messages) {
          errors.add(new SimpleMessage("test", message));
        }
        return value;
      }
    };
  }
View Full Code Here

    verify(response).addHeader("Location", "http://myapp.com/resource/method");
  }

  @Test
  public void shouldSerializeErrorMessages() throws Exception {
    Message normal = new SimpleMessage("category", "The message");
    I18nMessage i18ned = new I18nMessage("category", "message");
    i18ned.setBundle(new SingletonResourceBundle("message", "Something else"));

    XStreamBuilder xstreamBuilder = cleanInstance(new MessageConverter());
    MockSerializationResult result = new MockSerializationResult(null, xstreamBuilder, null, null);
View Full Code Here

    assertThat(serialized, not(containsString("<i18nMessage>")));
  }

  @Test
  public void shouldSerializeErrorMessagesInJSON() throws Exception {
    Message normal = new SimpleMessage("category", "The message");
    I18nMessage i18ned = new I18nMessage("category", "message");
    i18ned.setBundle(new SingletonResourceBundle("message", "Something else"));

    List<JsonSerializer<?>> gsonSerializers = new ArrayList<>();
    List<JsonDeserializer<?>> gsonDeserializers = new ArrayList<>();
View Full Code Here

      fail("Should throw an exception.");
    } catch (ValidationException e) {
      List<Message> errors = e.getErrors();
     
      assertThat(errors, hasSize(1));
      assertTrue(errors.contains(new SimpleMessage("login", "invalid_login_or_password")));
    }
  }
View Full Code Here

      String category = v.getPropertyPath().toString();
      if (isNullOrEmpty(alias)) {
        category = alias + "." + category;
      }

      add(new SimpleMessage(category, v.getMessage()));
    }
    return this;
  }
View Full Code Here

    final User currentUser = dao.find(login, password);

    // if no user is found, adds an error message to the validator
    // "invalid_login_or_password" is the message key from messages.properties,
    // and that key is used with the fmt taglib in index.jsp, for example: <fmt:message key="error.key">
    validator.check(currentUser != null, new SimpleMessage("login", "invalid_login_or_password"));
   
    // you can use "this" to redirect to another logic from this controller
    validator.onErrorUsePageOf(this).login();

    // the login was valid, add user to session
View Full Code Here

  public void addToMyList(User user, Music music) {
      User currentUser = userInfo.getUser();
      userDao.refresh(currentUser);
     
      validator.check(user.getLogin().equals(currentUser.getLogin()),
              new SimpleMessage("user", "you_cant_add_to_others_list"));

      validator.check(!currentUser.getMusics().contains(music),
              new SimpleMessage("music", "you_already_have_this_music"));

    validator.onErrorUsePageOf(UsersController.class).home();

    music = musicDao.load(music);
    currentUser.add(music);
View Full Code Here

TOP

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

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.