/** * 在 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); } } }
@ActionMethod( name = "create", successView = "index.vhtml", errorView = "NewAccountForm.vhtml", parameterClass = NewAccountParameterObject.class, httpMethod = ActionMethod.HttpMethod.POST) public void doPostCreate(ActionContext actionContext) throws Exception { 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()); try { accountBO.insertAccount(newAccount); } catch (Exception e) { // update failed throw e; } }