ホーム | ②InitBinder を複数準備し @RequestMapping別に使うSpringMVC技術の検証 »
2017年9月 2日
①Tera5 Validatior の検証、
tourreservation ~ ManageCustomerController で、
先ず、
@Inject
CustomerPassEqualsValidator passwordEqualsValidator;
以下でInitBinderし、
@InitBinder("customerForm")
public void initBinder(WebDataBinder webDataBinder) {
// add custom validators to default bean validations
webDataBinder.addValidators(passwordEqualsValidator, dateValidator);
}
から、以下のコントローラー
@TransactionTokenCheck(value = "create", type = TransactionTokenType.BEGIN)
@RequestMapping(value = "create", method = RequestMethod.POST, params = "confirm")
public String createConfirm(@Validated CustomerForm form,
BindingResult result) {
if (result.hasErrors()) {
return createRedo(form);
}
return "managecustomer/createConfirm";
}
でチェックする箇所 ↓
ここから org.springframework.validation.Validator 拡張の Validator を作成して、以下のように initBinder を試験
--
@Component
public class CustomerNameValidatorIKEDATEST implements Validator {
@Override
public boolean supports(Class<?> clazz) {
return (CustomerForm.class).isAssignableFrom(clazz);
}
@Override
public void validate(Object target, Errors errors) {
CustomerForm customer = (CustomerForm) target;
String name = customer.getCustomerName();
if ( name.length() >= 3 ) {
return;
}
if ( name.length() < 3) {
errors.rejectValue("customerName", "IncorrectName.inputName", "Name is larger than 3.(InitValidatorTEST T.IKEDA)");
}
}
}
///// appication-messages_en.properties //
label.tr.managereservation.confirmEditBtnMessage = Confirm Changes
# customized screen specific messages
Size.customerForm.customerKana = Size of Kana must be less than {1} characters.
Size.customerForm.customerName = Size of Name must be less than {1} characters.
Size.customerForm.customerJob = Size of Job must be less than {1} characters.
Size.customerForm.customerMail = Size of Mail must be less than {1} characters.
Pattern.customerForm.customerPass = Password must be Alphanumeric.
Pattern.customerForm.customerPassConfirm = Confirm Password must be Alphanumeric.
Pattern.customerForm.customerTel = Phone number must be Numeric characters.
Pattern.customerForm.customerKana = Kana must be full-width katakana.
Pattern.customerForm.customerName = Name must be entered in full-width characters.
NotEquals.customerPass = Password does not match.
IncorrectDate.customerBirth = Incorrect date entered
IncorrectDate.inputdate = Incorrect date entered
IncorrectName.inputName = Incorrect Name Length ( TEST IKEDA 20170902 ).
//////////////////////// Contoroller TEST //////////////////////////////////////////////////////////////////////////////////////////////////////////
@InitBinder("customerForm")
public void initBinder(WebDataBinder webDataBinder) {
webDataBinder.addValidators(passwordEqualsValidator, dateValidator, nameValidator);
}
トラックバック(0)
トラックバックURL: http://erikay.cho88.com/cms/mt-tb.cgi/39
コメントする