2007년 9월 10일 월요일

AbstractWizardFormController 사용기

단계별 Form 처리 컨트롤 - AbstractWizardFormController

소프트웨어 설치시 보면 한방에 설치가 되여지는것이 아닌 여러단계에 거쳐서 설치가 이루어진다. 보통보면 다음을 클릭하여 다음단계로 이동하고 완료를 클릭하여 설치를 끝마친다.
Spring Web MVC에도 이와 흡사한 방식으로 처리해주는 Controller가 있다.
그것이 바로 AbstractWizardFormController이다.

AbstractWizardFormController는 SimpleFormController와 비슷하며 그 메소드 구성만 봐도 거의 엇비슷한것을 발견할수 있다.
AbstractWizardFormController와 기타 컨트롤러 사이의 구별점을 열거하면 다음과 같다.

다시말하자면 AbstractWizardFormController는 요청을 통해 전해지는 사용자 입력값으로 폼 객체를 자동으로 설정하는 HTTP 폼 컨트롤러이다. 요청마다 새로운 폼 객체 인스턴스를 사용할 수도 있지만, sessionForm 속성을 true로 설정하면, 여러 차례의 요청 가운데서 객체를 공유할 수도 있다.

public AbstractWizardFormController() {
 // AbstractFormController sets default cache seconds to 0.
 super();

 // Always needs session to keep data from all pages.
 setSessionForm(true);

 // Never validate everything on binding ->
 // wizards validate individual pages.
 setValidateOnBinding(false);
}

  1. 폼 객체의 작용범위는 Session이며 sessionForm의 속성은 true이다. 왜냐면 여러페이지에 거쳐서 데이타를 손실없이 가지고 가야하니깐 request영역내에서만 데이타를 유지시키는것은 불가능한것이다.
  2. 또한 폼 데이타가 바인딩될때 데이타유효성체크를 하지 않는다. 즉 validateOnBinding속성이 false로 된다.
  3. 여러개 폼 뷰사이에서 전환이 가능하다.
  4. 상당히 명확한 웍프로세스 템플릿 메소드들을 가지고 있다. 예로, 처리를 완료할때는 processFinish()메소드를 호출하고 처리를 취소할때는 processCancel()메소드를 호출하면 된다.

위에 몇가지 사항들을 제외하고도 실제 해당 컨트롤러를 사용하기 위해서는 알아둬야 할점이 몇가지 있다.

/**
 * Parameter triggering the finish action.
 * Can be called from any wizard page!
 */
public static final String PARAM_FINISH = "_finish";

/**
 * Parameter triggering the cancel action.
 * Can be called from any wizard page!
 */
public static final String PARAM_CANCEL = "_cancel";

/**
 * Parameter specifying the target page,
 * appending the page number to the name.
 */
public static final String PARAM_TARGET = "_target";

/**
 * Parameter specifying the current page as value. Not necessary on
 * form pages, but allows to properly handle usage of the back button.
 * @see #setPageAttribute
 */
public static final String PARAM_PAGE = "_page";

내부적으로 프로세스 플러우를 처리하는 문자열 상수를 가지고 있는데 그것들로는
_finish, _cancel, _target, _page이다.
_finish는 임의의 폼페이지에서 호출이 되여질 수 있으며 폼 wizard를 끝마치고 싶을 때 호출한다.
_cancel또한 임의의 폼페이지에서 호출이 되여질 수 있으모 폼 wizard를 취소하고 싶을 때 호출한다.

/**
 * Set the wizard pages, i.e. the view names for the pages.
 * The array index is interpreted as page number.
 * @param pages view names for the pages
 */
public final void setPages(String[] pages) {
 if (pages == null || pages.length == 0)  {
  throw new IllegalArgumentException("No wizard pages defined");
 }
 this.pages = pages;
}

위저드 페이지를 세팅하는 메소드이다. 세팅된 페이지는 문자열 배열에 들어가지게 되고 문자열배열의 인덱스번호가 위저드 페이지 번호가 되여진다.

 /**
  * Set if "dirty back" is allowed, that is, if moving to a former wizard
  * page is allowed in case of validation errors for the current page.
  * @param allowDirtyBack if "dirty back" is allowed
  */
 public final void setAllowDirtyBack(boolean allowDirtyBack) {
  this.allowDirtyBack = allowDirtyBack;
 }

 /**
  * Set if "dirty forward" is allowed, that is, if moving to a later wizard
  * page is allowed in case of validation errors for the current page.
  * @param allowDirtyForward if "dirty forward" is allowed
  */
 public final void setAllowDirtyForward(boolean allowDirtyForward) {
  this.allowDirtyForward = allowDirtyForward;
 }

dirty back와 dirty forward 두가지 속성은 기본 dirty back = true로, dirty forward = false로 설정이 되여져 있는데 그 의미는 현재 머물고 있는 페이지에 validation 오류가 존재할 시 앞 혹은 뒤 페이지로의 이동 허용여부를 세팅한다. dirty back = true로 되여져있으면 현재 페이지에 validation 오류가 있을시 뒷페이지의 이동을 허용한다는 뜻이 되겠다.

댓글 없음:

댓글 쓰기