Example #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);
    }
  }
Example #2
0
  @ActionMethod(
      name = "newaccount",
      successView = "NewAccountForm.vhtml",
      httpMethod = ActionMethod.HttpMethod.GET)
  public void doGetNewAccount(ActionContext actionContext) throws Exception {
    // do nothing
    PageContext pageContext = actionContext.getPageContext();
    pageContext.setAttribute("languages", languages);

    List<Category> categories = categoryBO.getCategoryList();
    pageContext.setAttribute("categories", categories);
  }
Example #3
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);
  }
Example #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);
      }
    }
  }