diff --git a/src/main/java/kr/xit/framework/biz/mng/menu/web/ProgramMngController.java b/src/main/java/kr/xit/framework/biz/mng/menu/web/ProgramMngController.java index 8c4e2c38..2491a289 100644 --- a/src/main/java/kr/xit/framework/biz/mng/menu/web/ProgramMngController.java +++ b/src/main/java/kr/xit/framework/biz/mng/menu/web/ProgramMngController.java @@ -2,6 +2,7 @@ package kr.xit.framework.biz.mng.menu.web; import java.io.IOException; import java.util.HashMap; +import java.util.List; import java.util.Map; import javax.annotation.Resource; @@ -23,6 +24,8 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.ModelAndView; +import com.fasterxml.jackson.core.JsonProcessingException; + import egovframework.rte.ptl.mvc.tags.ui.pagination.PaginationInfo; import kr.xit.framework.biz.mng.menu.model.ProgramMngSearchVO; import kr.xit.framework.biz.mng.menu.model.ProgramMngVO; @@ -38,7 +41,10 @@ import kr.xit.framework.support.mybatis.MybatisUtils; import kr.xit.framework.support.util.AjaxMessageMapRenderer; import kr.xit.framework.support.util.AjaxUtils; import kr.xit.framework.support.util.Checks; +import kr.xit.framework.support.util.JsonUtil; +import kr.xit.framework.support.util.ValidationError; import kr.xit.framework.support.util.constants.MessageKey; +import kr.xit.framework.support.util.model.FieldErrorDtl; /** * @@ -124,11 +130,10 @@ public class ProgramMngController { ModelAndView mav = new ModelAndView(FrameworkConstants.JSON_VIEW); //유효성 확인 - beanValidator.validate(progrmMngVO, bindingResult); - // beanValidator.validate("progrmMngVO", vo, bindingResult); + beanValidator.validate("progrmMngVO", progrmMngVO, bindingResult); if (bindingResult.hasErrors()) { - throw BizRuntimeException.create(MessageKey.CMM_INSERT_FAIL); - + List dtls = ValidationError.errorList(bindingResult.getFieldErrors()); + throw BizRuntimeException.create("errors.required", new Object[]{dtls.get(0).getMessage()}); } programMngService.addProgram(progrmMngVO); diff --git a/src/main/java/kr/xit/framework/support/exception/BizRuntimeException.java b/src/main/java/kr/xit/framework/support/exception/BizRuntimeException.java index 35fa4aa8..cc8c0967 100644 --- a/src/main/java/kr/xit/framework/support/exception/BizRuntimeException.java +++ b/src/main/java/kr/xit/framework/support/exception/BizRuntimeException.java @@ -5,6 +5,7 @@ import javax.annotation.Resource; import org.springframework.context.support.MessageSourceAccessor; import org.springframework.validation.BindingResult; +import kr.xit.framework.support.util.Checks; import kr.xit.framework.support.util.JBeanRegistry; /** @@ -58,7 +59,8 @@ public class BizRuntimeException extends RuntimeException { BizRuntimeException ex = new BizRuntimeException(); ex.setCode(errorCode); - ex.setMessage(JBeanRegistry.getMessageSourceAccessor().getMessage(errorCode)); + if(Checks.isNotEmpty(arguments)) ex.setMessage(JBeanRegistry.getMessageSourceAccessor().getMessage(errorCode, arguments)); + else ex.setMessage(JBeanRegistry.getMessageSourceAccessor().getMessage(errorCode)); ex.setArguments(arguments); return ex; } diff --git a/src/main/java/kr/xit/framework/support/util/AjaxMessageMapRenderer.java b/src/main/java/kr/xit/framework/support/util/AjaxMessageMapRenderer.java index df8a76b5..ec5ee617 100644 --- a/src/main/java/kr/xit/framework/support/util/AjaxMessageMapRenderer.java +++ b/src/main/java/kr/xit/framework/support/util/AjaxMessageMapRenderer.java @@ -3,8 +3,12 @@ package kr.xit.framework.support.util; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; +import java.util.stream.Collectors; +import org.springframework.context.MessageSource; +import org.springframework.context.support.MessageSourceAccessor; import org.springframework.util.StringUtils; import org.springframework.validation.BindingResult; import org.springframework.validation.FieldError; @@ -13,6 +17,7 @@ import org.springframework.web.servlet.ModelAndView; import kr.xit.framework.support.exception.BizRuntimeException; import kr.xit.framework.support.util.constants.MessageGroupKey; import kr.xit.framework.support.util.constants.MessageKey; +import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import kr.xit.framework.support.util.constants.Globals; @@ -243,7 +248,7 @@ public abstract class AjaxMessageMapRenderer { } return list; } - + /** * Json 메시지 데이타 포맷을 각 성격에 맞게 생성한다. */ @@ -281,4 +286,5 @@ public abstract class AjaxMessageMapRenderer { return message; } } + } diff --git a/src/main/java/kr/xit/framework/support/util/ValidationError.java b/src/main/java/kr/xit/framework/support/util/ValidationError.java new file mode 100644 index 00000000..41a994c9 --- /dev/null +++ b/src/main/java/kr/xit/framework/support/util/ValidationError.java @@ -0,0 +1,38 @@ +package kr.xit.framework.support.util; + +import java.util.List; +import java.util.stream.Collectors; + +import org.springframework.validation.Errors; +import org.springframework.validation.FieldError; + +import kr.xit.framework.support.util.model.FieldErrorDtl; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +@AllArgsConstructor +public class ValidationError { + private List errors; + + public static ValidationError create(List errors){ + List dtls = errors.stream() + .map(FieldErrorDtl::create) + .collect(Collectors.toList()); + + return new ValidationError(dtls); + } + + public static List errorList(List errors){ + return errors.stream() + .map(FieldErrorDtl::create) + .collect(Collectors.toList()); + } + + public static String errorMessage(List errors){ + FieldError error = errors.get(0); + + } +} diff --git a/src/main/java/kr/xit/framework/support/util/model/FieldErrorDtl.java b/src/main/java/kr/xit/framework/support/util/model/FieldErrorDtl.java new file mode 100644 index 00000000..7fc01448 --- /dev/null +++ b/src/main/java/kr/xit/framework/support/util/model/FieldErrorDtl.java @@ -0,0 +1,37 @@ +package kr.xit.framework.support.util.model; + +import java.util.Locale; + +import org.springframework.context.MessageSource; +import org.springframework.validation.FieldError; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; + +/** + * Validation format에 맞게 에러 메세지 획득 + */ +@Getter +@Setter +@AllArgsConstructor +public class FieldErrorDtl { + + private String field; + + private String code; + + //private Object rejectedValue; + private String message; + + public static FieldErrorDtl create(FieldError fieldError) { + return new FieldErrorDtl( + fieldError.getField(), + fieldError.getCode(), + //fieldError.getRejectedValue(), + String.valueOf(fieldError.getArguments()[0]) + //fieldError.getDefaultMessage() + ); + } + + } diff --git a/src/main/webapp/WEB-INF/jsp/framework/biz/mng/menu/mngProgramMgtForm.jsp b/src/main/webapp/WEB-INF/jsp/framework/biz/mng/menu/mngProgramMgtForm.jsp index 065a490c..cd46a68d 100644 --- a/src/main/webapp/WEB-INF/jsp/framework/biz/mng/menu/mngProgramMgtForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/framework/biz/mng/menu/mngProgramMgtForm.jsp @@ -21,18 +21,18 @@ - - - - - - - + + + + + + +
검색조건
프로그램 한글명 - + diff --git a/src/main/webapp/WEB-INF/jsp/framework/biz/mng/menu/mngProgramMgtPopup.jsp b/src/main/webapp/WEB-INF/jsp/framework/biz/mng/menu/mngProgramMgtPopup.jsp index 1af88fc8..1c31ec95 100644 --- a/src/main/webapp/WEB-INF/jsp/framework/biz/mng/menu/mngProgramMgtPopup.jsp +++ b/src/main/webapp/WEB-INF/jsp/framework/biz/mng/menu/mngProgramMgtPopup.jsp @@ -18,51 +18,55 @@

프로그램 상세조회 /수정

+ + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + +
프로그램 상세조회 /수정
- - - - - - - - - - - - - -
- - - -
- - - -
- - - -
- - -
+ + + + + + + + + + + +
+ + + +
+ + + +
+ + + +
+ + +
- -