sitelink1 | |
---|---|
sitelink2 | |
extra_vars5 | |
extra_vars6 |
package com.ibatis.struts;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionError;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
/**
* All actions mapped through the BeanAction class should be mapped
* to a subclass of BaseBean (or have no form bean mapping at all).
*
* The BaseBean class simplifies the validate() and reset() methods
* by allowing them to be managed without Struts dependencies. Quite
* simply, subclasses can override the parameterless validate()
* and reset() methods and set errors and messages using the ActionContext
* class.
*
* Note: Full error, message and internationalization support is not complete.
*
* Date: Mar 12, 2004 9:20:39 PM
*
* @author Clinton Begin
*/
public abstract class BaseBean extends ActionForm {
public void reset(ActionMapping mapping, ServletRequest request) {
ActionContext.initialize((HttpServletRequest)request, null);
reset();
}
public void reset(ActionMapping mapping, HttpServletRequest request) {
ActionContext.initialize((HttpServletRequest)request, null);
reset();
}
public ActionErrors validate(ActionMapping mapping, ServletRequest request) {
ActionContext.initialize((HttpServletRequest)request, null);
ActionContext ctx = ActionContext.getActionContext();
Map requestMap = ctx.getRequestMap();
List errorList = null;
requestMap.put("errors",errorList);
validate();
errorList = (List) requestMap.get("errors");
ActionErrors actionErrors = null;
if (errorList != null && !errorList.isEmpty()) {
actionErrors = new ActionErrors();
actionErrors.add(ActionErrors.GLOBAL_ERROR, new ActionError("global.error"));
}
return actionErrors;
}
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
ActionContext.initialize(request, null);
ActionContext ctx = ActionContext.getActionContext();
Map requestMap = ctx.getRequestMap();
List errorList = null;
requestMap.put("errors",errorList);
validate();
errorList = (List) requestMap.get("errors");
ActionErrors actionErrors = null;
if (errorList != null && !errorList.isEmpty()) {
actionErrors = new ActionErrors();
actionErrors.add(ActionErrors.GLOBAL_ERROR, new ActionError("global.error"));
}
return actionErrors;
}
public void validate() {
}
public void reset() {
}
public void clear() {
}
protected void validateRequiredField(String value, String errorMessage) {
if (value == null || value.trim().length() < 1) {
ActionContext.getActionContext().addSimpleError(errorMessage);
}
}
}
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionError;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
/**
* All actions mapped through the BeanAction class should be mapped
* to a subclass of BaseBean (or have no form bean mapping at all).
*
* The BaseBean class simplifies the validate() and reset() methods
* by allowing them to be managed without Struts dependencies. Quite
* simply, subclasses can override the parameterless validate()
* and reset() methods and set errors and messages using the ActionContext
* class.
*
* Note: Full error, message and internationalization support is not complete.
*
* Date: Mar 12, 2004 9:20:39 PM
*
* @author Clinton Begin
*/
public abstract class BaseBean extends ActionForm {
public void reset(ActionMapping mapping, ServletRequest request) {
ActionContext.initialize((HttpServletRequest)request, null);
reset();
}
public void reset(ActionMapping mapping, HttpServletRequest request) {
ActionContext.initialize((HttpServletRequest)request, null);
reset();
}
public ActionErrors validate(ActionMapping mapping, ServletRequest request) {
ActionContext.initialize((HttpServletRequest)request, null);
ActionContext ctx = ActionContext.getActionContext();
Map requestMap = ctx.getRequestMap();
List errorList = null;
requestMap.put("errors",errorList);
validate();
errorList = (List) requestMap.get("errors");
ActionErrors actionErrors = null;
if (errorList != null && !errorList.isEmpty()) {
actionErrors = new ActionErrors();
actionErrors.add(ActionErrors.GLOBAL_ERROR, new ActionError("global.error"));
}
return actionErrors;
}
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
ActionContext.initialize(request, null);
ActionContext ctx = ActionContext.getActionContext();
Map requestMap = ctx.getRequestMap();
List errorList = null;
requestMap.put("errors",errorList);
validate();
errorList = (List) requestMap.get("errors");
ActionErrors actionErrors = null;
if (errorList != null && !errorList.isEmpty()) {
actionErrors = new ActionErrors();
actionErrors.add(ActionErrors.GLOBAL_ERROR, new ActionError("global.error"));
}
return actionErrors;
}
public void validate() {
}
public void reset() {
}
public void clear() {
}
protected void validateRequiredField(String value, String errorMessage) {
if (value == null || value.trim().length() < 1) {
ActionContext.getActionContext().addSimpleError(errorMessage);
}
}
}
댓글 0
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
11 | StrutsTest를 이용한 JUnit 테스트방법 | 황제낙엽 | 2006.02.23 | 104 |
10 | 스트러츠등의 서블릿 테스트 케이스용 툴 | 황제낙엽 | 2006.02.23 | 75 |
9 | ActionForm 생성 | 황제낙엽 | 2006.01.16 | 77 |
8 | Struts 에서 FormBean 클래스 Validation 체크 하기 | 황제낙엽 | 2005.12.19 | 71 |
7 | Struts의 message-resources 를 사용한 예제 | 황제낙엽 | 2005.12.16 | 70 |
6 | Struts의 message-resources 의 사용 | 황제낙엽 | 2005.12.16 | 85 |
» | JpetStore 에서 모든 Bean의 부모클래스 BaseBean (JPetStore-4.0.5) | 황제낙엽 | 2005.11.21 | 125 |
4 | JpetStore 에서 Action과 Form을 함께 취급하는 클래스 BeanAction (JPetStore-4.0.5) | 황제낙엽 | 2005.11.21 | 160 |
3 | 스트럿츠 자료실 게시판 만들기 목차 | 황제낙엽 | 2005.11.15 | 99 |
2 | 스트러츠 관련 FAQ | 황제낙엽 | 2005.10.14 | 61 |
1 | Struts 프로그래밍 메모 | 황제낙엽 | 2005.10.06 | 180 |