Ejemplo n.º 1
0
  /**
   * Check user name availability. UI ajax use.
   *
   * @param ajax event
   * @return
   */
  public boolean checkAvailable(AjaxBehaviorEvent event) {

    InputText inputText = (InputText) event.getSource();
    String value = (String) inputText.getValue();

    boolean available = userDao.checkAvailable(value);

    if (!available) {
      FacesMessage message =
          constructErrorMessage(
              null, String.format(getMessageBundle().getString("userExistsMsg"), value));
      getFacesContext().addMessage(event.getComponent().getClientId(), message);
    } else {
      FacesMessage message =
          constructInfoMessage(
              null, String.format(getMessageBundle().getString("userAvailableMsg"), value));
      getFacesContext().addMessage(event.getComponent().getClientId(), message);
    }

    return available;
  }
Ejemplo n.º 2
0
  /**
   * Create user - persist to database
   *
   * @param userEntity
   * @return true if success
   */
  public boolean createUser(UserEntity userEntity) {

    if (!userDao.checkAvailable(userEntity.getUserName())) {
      FacesMessage message =
          constructErrorMessage(
              String.format(
                  getMessageBundle().getString("userExistsMsg"), userEntity.getUserName()),
              null);
      getFacesContext().addMessage(null, message);

      return false;
    }

    try {
      userDao.save(userEntity);
    } catch (Exception e) {
      FacesMessage message = constructFatalMessage(e.getMessage(), null);
      getFacesContext().addMessage(null, message);

      return false;
    }

    return true;
  }