Controller 예제

개발자가 Ajax(Nitobi)를 이용하여 UI 화면을 구성 할 때에는 AnyframeFormController대신 AnyframeAjaxController를 이용한다.
이 장에서는 조회/저장 시 Controller클래스를 어떻게 작성하는지 설명한다.

조회

AnyframeAjaxController의 조회

public class SaleController extends AnyframeAjaxController {
<!-- 중략 -->
  public ModelAndView list(HttpServletRequest request,
    HttpServletResponse response) throws Exception {
       
    SearchVO searchVO = new SearchVO();
       
    getRequestParams(request, searchVO, "product_no");
    bind(request, searchVO);
       
    ArrayList categoryList =
        (ArrayList) categoryService.getCategoryListAll(searchVO);
           
    getHandler.populate(categoryList, CategoryVO.class);
    getHandler.writeToClient(response);

    return null;
  }
<!-- 중략 -->
}
Client -> Server parameter전달

Client에서 Get방식으로 전달한 parameter들을 getRequestParams메소드를 호출하여
조회 조건을 위한 VO에 세팅한다. 이 때 조회 조건을 위한 VO(SearchVO)는 AnyframeAjaxCommonSearchVO를 상속 받아야 한다.
bind메소드를 호출하며 나머지 parameter(검색 조건, 검색어)를 VO 객체에 세팅한다.
*위 샘플 코드에서 getRequestParams의 argument인 "product_no"는 처음 Ajax Component가 로딩 될 때 기본으로 정렬할 컬럼 명이다.

Server-> Client 조회Data전달

VO List를 AnyframeGetHandler의 populate메소드를 이용해 XML로 전환 후 Client에 전달 한다.

저장

AnyframeAjaxController의 저장

public class SaleController extends AnyframeAjaxController {
<!-- 중략 -->
    public ModelAndView save(HttpServletRequest request, HttpServletResponse response) throws Exception {
        
        AnyframeSaveHandler saveHandler= new AnyframeSaveHandler(request);
        
        HashMap recordMap = new HashMap();
        getRecords(request ,saveHandler, recordMap);
        
		categoryService.updateCategory(recordMap);
        
        saveHandler.setErrorMessage("save successed");
        saveHandler.writeToClient(response);
        
        return null;
	}
}
Client -> Server 변경Data전달

Client에서 전달 된 XML을 getRecords메소드를 이용하여 유형별 Record가 담긴 HashMap객체로 전환한다.
HashMap객체는 “insertRecords”,”updateRecords”,”deleteRecords”를 Key로 각각 유형별 Record를 갖고 있다.
유형별 Record가 담긴 HashMap에 대한 Biz. Service는 Anyframe Core의 RIA Query를 참조한다.