개발자는 일반 JSP환경에서 DefaultActionSupport를 상속받아 Control을 구현하나 MiPlatform환경에서는 DefaultMIActionSupport를 이용한다.
이 장에서는 조회시 Action예제가 JSP환경과 MiPlatform환경에서 어떤 차이점을 갖는지 설명한다.
public class GetCategoryAction extends DefaultActionSupport {
public ActionForward process(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
ApplicationContext ctx = getWebApplicationContext();
CategoryService categoryService = (CategoryService) ctx
.getBean("categoryService");
CategoryForm categoryForm = (CategoryForm) form;
String categoryNo = categoryForm.getCategoryNo();
CategoryVO categoryVO = categoryService.getCategory(categoryNo);
request.setAttribute("categoryVO", categoryVO);
return mapping.findForward("success");
}
}
Client에서 submit된 Form기반의 ActionForm을 BeanUtil을 이용하여 VO object로 변환하여 Biz. Service실행시 이용한다.
VO를 HttpServletRequest 객체에 입력하여 jsp에서 이용가능하도록 한다.
public class GetCategoryListMIAction extends DefaultMIActionSupport {
public void operate(HttpServletRequest request, VariableList in_vl,
DatasetList in_dl, VariableList out_vl, DatasetList out_dl)
throws Exception {
ApplicationContext ctx = getWebApplicationContext();
CategoryService categoryService = (CategoryService) ctx
.getBean("categoryService");
String categoryNo = in_vl.getValueAsString("searchCondition");
List changeList = (List)categoryService.getCategory(searchVO);
if(changeList == null || changeList .size() < 1) {
throw new Exception("데이터가 없습니다");
} else {
out_dl.addDataset("ds_access",
createDataSet(changeList , "ds_access"));
}
}
}
Client에서 Get방식으로 전달한 parameter를 VariableList in_vl에서 getValueAsString()함수를 이용하며 추출가능하다.
VO를 createDataSet() 메소드를 이용하여 Dataset객체로 전환 후 DatasetList out_dl 에 입력하여 전달한다.
public class UpdateCategoryAction extends DefaultActionSupport {
public ActionForward process(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
ApplicationContext ctx = getWebApplicationContext();
CategoryService categoryService = (CategoryService) ctx
.getBean("categoryService");
CategoryVO categoryVO = new CategoryVO();
CategoryForm categoryForm = (CategoryForm) form;
BeanUtils.copyProperties(categoryVO, categoryForm);
categoryService.updateCategory(categoryVO);
return mapping.findForward("success");
}
}
Client에서 submit된 Form기반의 ActionForm을 BeanUtil을 이용하여 VO object로 변환하여 Biz. Service에 전달한다.
public class UpdateCategoryListMIAction extends DefaultMIActionSupport {
public void operate(HttpServletRequest request, VariableList in_vl,
DatasetList in_dl, VariableList out_vl, DatasetList out_dl)
throws Exception {
ApplicationContext ctx = getWebApplicationContext();
CategoryService categoryService = (CategoryService) ctx
.getBean("categoryService");
Dataset ds = in_dl.getDataset("ds_input");
HashMap changeMap =createVOMap(ds, CategoryVO.class);
categoryService.processAll(changeMap);
}
}
Client에서 post된 Dataset을 createVOMap() 메소드를 이용하여 유형별 VO List가 담긴 HashMap객체로 전환할 수 있으며
HashMap객체는 “insert”,”update”,”delete”를 Key로 각각 유형별 VO List를 갖고 있다.