Anyframe Web에서는 Action 클래스에서 공통적으로 적용되는 기능에 대한 Template 클래스로 DefaultActionSupport를 제공한다.
DefaultActionSupport의 기능을 그대로 가지면서 Struts의 DispatchAction과 같이 동작할 수 있는 DefaultDispatchActionSupport 도 함께 제공하고 있다.
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
ActionForward forward = null;
try {
preProcess(mapping, form, request, response);
getLogger().debug("\n\n" + this.getClass().getName()
+ ".process() Started!");
forward = process(mapping, form, request, response);
getLogger().debug("\n\n" + this.getClass().getName()
+ ".process() Ended!");
forward = postProcess(mapping, form, request, response, forward);
} catch (InvalidTokenException tokenException) {
getLogger().debug("\n InvalidTokenException catch!!");
forward = processInvalidTokenException(mapping, form, request,
response, tokenException);
} catch (RuntimeException uncheckedException) {
getLogger().debug("\n RuntimeException catch!!");
forward = processUnCheckedException(mapping, form, request,
response, uncheckedException);
} catch (Exception checkedException) {
getLogger().debug("\n Action Support Exception catch!!");
forward = processCheckedException(mapping, form, request, response,
checkedException);
} finally {
getLogger().debug("\n Finally !!");
forward = processFinally(mapping, form, request, response, forward);
}
return forward;
}
public class UpdateUserAction extends DefaultActionSupport {
public Log getLogger() throws Exception {
return DefaultActionUtils.getLogger(this.getClass().getName());
}
public ActionForward process(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
ApplicationContext ctx = getWebApplicationContext();
UserService userService = (UserService) ctx.getBean("userService");
UserVO userVO = new UserVO();
UserForm userForm = (UserForm) form;
BeanUtils.copyProperties(userVO, userForm);
userService.updateUser(userVO);
if (EmpUtil.null2str(request.getParameter("flag")).equals("admin")) {
return mapping.findForward("success_list");
}
else {
return mapping.findForward("success_update");
}
}
}
public class UserAction extends DefaultDispatchActionSupport {
private Log logger;
public UserAction() {
try {
logger = this.getLogger();
} catch(Exception e) {
}
}
public Log getLogger() throws Exception {
return DefaultActionUtils.getLogger(this.getClass().getName());
}
public ActionForward add(ActionMapping mapping, ActionForm form,
...
return mapping.findForward("success");
}
public ActionForward addUserView(ActionMapping mapping, ActionForm form,
...
return mapping.findForward("success");
}
public ActionForward checkDuplication(ActionMapping mapping, ActionForm form,
...
return mapping.findForward("success");
}
public ActionForward getUser(ActionMapping mapping, ActionForm form,
...
return mapping.findForward("get");
}
public ActionForward getUserList(ActionMapping mapping, ActionForm form,
...
return mapping.findForward("list");
}
public ActionForward updateUser(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
ApplicationContext ctx = getWebApplicationContext();
UserService userService = (UserService) ctx.getBean("userService");
UserVO userVO = new UserVO();
UserForm userForm = (UserForm) form;
BeanUtils.copyProperties(userVO, userForm);
userService.updateUser(userVO);
if (EmpUtil.null2str(request.getParameter("flag")).equals("admin")) {
return mapping.findForward("success_list");
}
else {
return mapping.findForward("success_update");
}
}
}