Ejemplo n.º 1
0
  @ActionMethod(
      name = "signon",
      successView = "index.vhtml",
      errorView = "signon.vhtml",
      parameterClass = SignonParameterObject.class,
      httpMethod = ActionMethod.HttpMethod.POST)
  public void doPostSignon(ActionContext actionContext) throws Exception {
    SignonParameterObject invocation = (SignonParameterObject) actionContext.getParameterObject();

    Account account =
        (Account)
            loginService.login(
                actionContext.getSessionContext(),
                this,
                invocation.getUsername(),
                invocation.getPassword());
    if (account == null) {
      String msg = "Invalid username or password. Signon failed";
      PageContext pageContext = actionContext.getPageContext();
      pageContext.setAttribute("errorMessage", msg);
      throw new Exception(msg);
    } else {
      SessionContext sessionContext = actionContext.getSessionContext();
      sessionContext.setAttribute(ACCOUNT_SESSION_KEY, account);
    }
  }
Ejemplo n.º 2
0
 @ActionMethod(
     name = "signoff",
     successView = "index.vhtml",
     httpMethod = ActionMethod.HttpMethod.GET)
 public void doGetSignoff(ActionContext actionContext) throws Exception {
   SessionContext sessionContext = actionContext.getSessionContext();
   sessionContext.clearAttributes();
   actionContext.destroySessionContext();
 }
Ejemplo n.º 3
0
  @ActionMethod(
      name = "edit",
      successView = "index.vhtml",
      errorView = "EditAccount.vhtml",
      parameterClass = EditAccountParameterObject.class,
      httpMethod = ActionMethod.HttpMethod.POST)
  public void doPostEdit(ActionContext actionContext) throws Exception {
    EditAccountParameterObject invocation =
        (EditAccountParameterObject) actionContext.getParameterObject();

    SessionContext sessionContext = actionContext.getSessionContext();
    Account account = (Account) sessionContext.getAttribute(ACCOUNT_SESSION_KEY);

    Account newAccount = new Account();
    newAccount.setBannerName(account.getBannerName());
    newAccount.setUsername(account.getUsername());
    newAccount.setStatus(account.getStatus());

    newAccount.setPassword(invocation.getPassword());
    newAccount.setAddress1(invocation.getAddress1());
    newAccount.setAddress2(invocation.getAddress2());
    newAccount.setBannerOption(invocation.getBannerOption());
    newAccount.setCity(invocation.getCity());
    newAccount.setCountry(invocation.getCountry());
    newAccount.setEmail(invocation.getEmail());
    newAccount.setFavouriteCategoryId(invocation.getFavouriteCategoryId());
    newAccount.setFirstName(invocation.getFirstName());
    newAccount.setLanguagePreference(invocation.getLanguagePreference());
    newAccount.setLastName(invocation.getLastName());
    newAccount.setListOption(invocation.getListOption());
    newAccount.setPassword(invocation.getPassword());
    newAccount.setPhone(invocation.getPhone());
    newAccount.setState(invocation.getState());
    newAccount.setZip(invocation.getZip());

    try {
      accountBO.updateAccount(newAccount);
      sessionContext.setAttribute(ACCOUNT_SESSION_KEY, newAccount);
    } catch (Exception e) {
      // update failed
      throw e;
    }
  }
Ejemplo n.º 4
0
  /**
   * 在 doPostEdit 发生异常时,通过该方法设置 PageContext account, 以便跳转到 errorView 时,可以预设数据
   *
   * @param actionContext invocationContext
   */
  public void doActionFailed(ActionContext actionContext) {
    if (actionContext.getActionMethod().getName().equals("doPostEdit")) {
      SessionContext sessionContext = actionContext.getSessionContext();
      Account account = (Account) sessionContext.getAttribute(ACCOUNT_SESSION_KEY);

      PageContext pageContext = actionContext.getPageContext();
      pageContext.setAttribute("account", account);
      pageContext.setAttribute("languages", languages);

      List<Category> categories = categoryBO.getCategoryList();
      pageContext.setAttribute("categories", categories);
    } else if (actionContext.getActionMethod().getName().equals("doPostCreate")) {
      NewAccountParameterObject invocation =
          (NewAccountParameterObject) actionContext.getParameterObject();
      Account newAccount = EntityFactory.newEntityObject(Account.class);
      newAccount.setUsername(invocation.getUsername());
      newAccount.setStatus("OK");
      newAccount.setPassword(invocation.getPassword());
      newAccount.setAddress1(invocation.getAddress1());
      newAccount.setAddress2(invocation.getAddress2());
      newAccount.setBannerOption(invocation.getBannerOption());
      newAccount.setCity(invocation.getCity());
      newAccount.setCountry(invocation.getCountry());
      newAccount.setEmail(invocation.getEmail());
      newAccount.setFavouriteCategoryId(invocation.getFavouriteCategoryId());
      newAccount.setFirstName(invocation.getFirstName());
      newAccount.setLanguagePreference(invocation.getLanguagePreference());
      newAccount.setLastName(invocation.getLastName());
      newAccount.setListOption(invocation.getListOption());
      newAccount.setPassword(invocation.getPassword());
      newAccount.setPhone(invocation.getPhone());
      newAccount.setState(invocation.getState());
      newAccount.setZip(invocation.getZip());
      PageContext pageContext = actionContext.getPageContext();
      pageContext.setAttribute("account", newAccount);
      try {
        doGetNewAccount(actionContext);
      } catch (Exception e) {
        logger.error("doActionFailed error.", e);
      }
    }
  }
Ejemplo n.º 5
0
  @ActionMethod(
      name = "editaccount",
      successView = "EditAccount.vhtml",
      errorView = "signon.vhtml",
      httpMethod = ActionMethod.HttpMethod.GET)
  public void doGetEditAccount(ActionContext actionContext) throws Exception {
    SessionContext sessionContext = actionContext.getSessionContext();
    Account account = (Account) sessionContext.getAttribute(ACCOUNT_SESSION_KEY);

    if (account == null) {
      throw new IllegalArgumentException("Not login, please login first!");
    }

    PageContext pageContext = actionContext.getPageContext();
    pageContext.setAttribute("account", account);
    pageContext.setAttribute("languages", languages);

    List<Category> categories = categoryBO.getCategoryList();
    pageContext.setAttribute("categories", categories);
  }