Beispiel #1
0
  @Override
  protected boolean processFormSubmit(
      AjaxRequestTarget target, AdminBackingBean backingBean, AjaxEventType type) throws Exception {
    UserManageBackingBean userManageBackingBean = (UserManageBackingBean) backingBean;

    boolean eventHandled;

    try {
      User user = userManageBackingBean.getUser();
      eventHandled = false;

      if (type == USER_CREATED) {
        userService.persistNewUser(user, user.getPassword());
      } else if (type == USER_UPDATED) {
        userService.persistEditedUser(user);

        String password = user.getPassword();
        if (StringUtils.isNotBlank(password)) {
          userService.changePassword(user.getUsername(), password);
        }
      } else if (type == USER_DELETED) {
        deleteUser(userManageBackingBean);
      }
    } catch (ObjectNotUniqueException obnu) {
      backingBean.setServerMessage(obnu.getMessage());
      target.add(this);
      eventHandled = true;
    }

    return !eventHandled;
  }
  /*
   * (non-Javadoc)
   * @see net.rrm.ehour.persistence.persistence.ui.common.ajax.AjaxAwareContainer#ajaxEventReceived(net.rrm.ehour.persistence.persistence.ui.common.ajax.AjaxEvent)
   */
  @Override
  @SuppressWarnings("unchecked")
  public boolean ajaxEventReceived(AjaxEvent ajaxEvent) {
    if (ajaxEvent.getEventType() == CommonAjaxEventType.SUBMIT_ERROR) {
      return processFormSubmitError(ajaxEvent.getTarget());
    } else if (ajaxEvent instanceof PayloadAjaxEvent) {
      PayloadAjaxEvent<AdminBackingBean> payloadEvent =
          (PayloadAjaxEvent<AdminBackingBean>) ajaxEvent;

      AdminBackingBean backingBean = payloadEvent.getPayload();
      AjaxEventType type = ajaxEvent.getEventType();
      AjaxRequestTarget target = ajaxEvent.getTarget();

      try {
        processFormSubmit(target, backingBean, type);

      } catch (Exception e) {
        logger.error("While trying to persist/delete", e);
        backingBean.setServerMessage(getLocalizer().getString("general.saveError", this));
        target.add(this);

        return false;
      }
    }

    return true;
  }