/** * Determine whether the given {@code @InitBinder} method should be used * to initialize the given {@link WebDataBinder} instance. By default we * check the specified attribute names in the annotation value, if any. */ protected boolean isBinderMethodApplicable(HandlerMethod initBinderMethod, WebDataBinder dataBinder) { InitBinder ann = initBinderMethod.getMethodAnnotation(InitBinder.class); Assert.state(ann != null, "No InitBinder annotation"); String[] names = ann.value(); return (ObjectUtils.isEmpty(names) || ObjectUtils.containsElement(names, dataBinder.getObjectName())); }
/** * Determine whether the given {@code @InitBinder} method should be used * to initialize the given {@link WebDataBinder} instance. By default we * check the specified attribute names in the annotation value, if any. */ protected boolean isBinderMethodApplicable(HandlerMethod initBinderMethod, WebDataBinder dataBinder) { InitBinder ann = initBinderMethod.getMethodAnnotation(InitBinder.class); Assert.state(ann != null, "No InitBinder annotation"); String[] names = ann.value(); return (ObjectUtils.isEmpty(names) || ObjectUtils.containsElement(names, dataBinder.getObjectName())); }
ParamNameDataBinder paramNameDataBinder = new ParamNameDataBinder(target, binder.getObjectName(), mapping); requestMappingHandlerAdapter.getWebBindingInitializer().initBinder(paramNameDataBinder, nativeWebRequest); super.bindRequestParameters(paramNameDataBinder, nativeWebRequest);
/** * Whether the given {@code @InitBinder} method should be used to initialize * the given WebDataBinder instance. By default we check the attributes * names of the annotation, if present. */ protected boolean isBinderMethodApplicable(HandlerMethod binderMethod, WebDataBinder binder) { InitBinder annot = binderMethod.getMethodAnnotation(InitBinder.class); Collection<String> names = Arrays.asList(annot.value()); return (names.size() == 0 || names.contains(binder.getObjectName())); }
/** * Determine whether the given {@code @InitBinder} method should be used * to initialize the given {@link WebDataBinder} instance. By default we * check the specified attribute names in the annotation value, if any. */ protected boolean isBinderMethodApplicable(HandlerMethod initBinderMethod, WebDataBinder dataBinder) { InitBinder ann = initBinderMethod.getMethodAnnotation(InitBinder.class); Assert.state(ann != null, "No InitBinder annotation"); String[] names = ann.value(); return (ObjectUtils.isEmpty(names) || ObjectUtils.containsElement(names, dataBinder.getObjectName())); }
/** * Determine whether the given {@code @InitBinder} method should be used * to initialize the given {@link WebDataBinder} instance. By default we * check the specified attribute names in the annotation value, if any. */ protected boolean isBinderMethodApplicable(HandlerMethod initBinderMethod, WebDataBinder dataBinder) { InitBinder ann = initBinderMethod.getMethodAnnotation(InitBinder.class); Assert.state(ann != null, "No InitBinder annotation"); String[] names = ann.value(); return (ObjectUtils.isEmpty(names) || ObjectUtils.containsElement(names, dataBinder.getObjectName())); }
@InitBinder public void initListBinder(WebDataBinder binder) { if (MODEL_MAILMESSAGE.equals(binder.getObjectName())) { Validator validator = new Validator() { @Override public void validate(Object target, Errors errors) { MailMessageData messageData = (MailMessageData) target; final long count = messageData.getReceiversList().stream().filter(r -> r.isActive()).count(); if (MAX_MAIL_RECEIVERS < count) { errors.rejectValue("receivers", MessageConstants.MESSAGE_USER_EMAIL_TOO_MANY_RECEIVERS, new Object[] { MAX_MAIL_RECEIVERS }, null); } } @Override public boolean supports(Class<?> clazz) { return MailMessageData.class.isAssignableFrom(clazz); } }; binder.addValidators(validator); } }
ServletRequestDataBinder kebabCaseDataBinder = new KebabCaseRequestDataBinder(target, binder.getObjectName(), mapping); requestMappingHandlerAdapter.getWebBindingInitializer().initBinder(kebabCaseDataBinder, nativeWebRequest); super.bindRequestParameters(kebabCaseDataBinder, nativeWebRequest);