org.springframework.validation.MessageCodesResolver Java Examples

The following examples show how to use org.springframework.validation.MessageCodesResolver. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebMvcConfigurerComposite.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
@Nullable
public MessageCodesResolver getMessageCodesResolver() {
	MessageCodesResolver selected = null;
	for (WebMvcConfigurer configurer : this.delegates) {
		MessageCodesResolver messageCodesResolver = configurer.getMessageCodesResolver();
		if (messageCodesResolver != null) {
			if (selected != null) {
				throw new IllegalStateException("No unique MessageCodesResolver found: {" +
						selected + ", " + messageCodesResolver + "}");
			}
			selected = messageCodesResolver;
		}
	}
	return selected;
}
 
Example #2
Source File: WebMvcConfigurerComposite.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
@Nullable
public MessageCodesResolver getMessageCodesResolver() {
	MessageCodesResolver selected = null;
	for (WebMvcConfigurer configurer : this.delegates) {
		MessageCodesResolver messageCodesResolver = configurer.getMessageCodesResolver();
		if (messageCodesResolver != null) {
			if (selected != null) {
				throw new IllegalStateException("No unique MessageCodesResolver found: {" +
						selected + ", " + messageCodesResolver + "}");
			}
			selected = messageCodesResolver;
		}
	}
	return selected;
}
 
Example #3
Source File: WebFluxConfigurationSupport.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Return the {@link ConfigurableWebBindingInitializer} to use for
 * initializing all {@link WebDataBinder} instances.
 */
protected ConfigurableWebBindingInitializer getConfigurableWebBindingInitializer(
		FormattingConversionService webFluxConversionService,
		Validator webFluxValidator) {
	ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
	initializer.setConversionService(webFluxConversionService);
	initializer.setValidator(webFluxValidator);
	MessageCodesResolver messageCodesResolver = getMessageCodesResolver();
	if (messageCodesResolver != null) {
		initializer.setMessageCodesResolver(messageCodesResolver);
	}
	return initializer;
}
 
Example #4
Source File: WebFluxConfigurationSupport.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Return the {@link ConfigurableWebBindingInitializer} to use for
 * initializing all {@link WebDataBinder} instances.
 */
protected ConfigurableWebBindingInitializer getConfigurableWebBindingInitializer() {
	ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
	initializer.setConversionService(webFluxConversionService());
	initializer.setValidator(webFluxValidator());
	MessageCodesResolver messageCodesResolver = getMessageCodesResolver();
	if (messageCodesResolver != null) {
		initializer.setMessageCodesResolver(messageCodesResolver);
	}
	return initializer;
}
 
Example #5
Source File: AnnotationDrivenBeanDefinitionParserTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testMessageCodesResolver() {
	loadBeanDefinitions("mvc-config-message-codes-resolver.xml");
	RequestMappingHandlerAdapter adapter = this.appContext.getBean(RequestMappingHandlerAdapter.class);
	assertNotNull(adapter);
	Object initializer = adapter.getWebBindingInitializer();
	assertNotNull(initializer);
	MessageCodesResolver resolver =
			((ConfigurableWebBindingInitializer) initializer).getMessageCodesResolver();
	assertNotNull(resolver);
	assertEquals(TestMessageCodesResolver.class, resolver.getClass());
	assertEquals(false, new DirectFieldAccessor(adapter).getPropertyValue("ignoreDefaultModelOnRedirect"));
}
 
Example #6
Source File: WebMvcConfigurationSupportExtensionTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@SuppressWarnings("serial")
@Override
public MessageCodesResolver getMessageCodesResolver() {
	return new DefaultMessageCodesResolver() {
		@Override
		public String[] resolveMessageCodes(String errorCode, String objectName) {
			return new String[] { "custom." + errorCode };
		}
	};
}
 
Example #7
Source File: WebMvcConfigurationSupport.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Return the {@link ConfigurableWebBindingInitializer} to use for
 * initializing all {@link WebDataBinder} instances.
 */
protected ConfigurableWebBindingInitializer getConfigurableWebBindingInitializer(
		FormattingConversionService mvcConversionService,
		Validator mvcValidator) {
	ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
	initializer.setConversionService(mvcConversionService);
	initializer.setValidator(mvcValidator);
	MessageCodesResolver messageCodesResolver = getMessageCodesResolver();
	if (messageCodesResolver != null) {
		initializer.setMessageCodesResolver(messageCodesResolver);
	}
	return initializer;
}
 
Example #8
Source File: AnnotationDrivenBeanDefinitionParserTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testMessageCodesResolver() {
	loadBeanDefinitions("mvc-config-message-codes-resolver.xml");
	RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
	assertNotNull(adapter);
	Object initializer = adapter.getWebBindingInitializer();
	assertNotNull(initializer);
	MessageCodesResolver resolver = ((ConfigurableWebBindingInitializer) initializer).getMessageCodesResolver();
	assertNotNull(resolver);
	assertEquals(TestMessageCodesResolver.class, resolver.getClass());
	assertEquals(false, new DirectFieldAccessor(adapter).getPropertyValue("ignoreDefaultModelOnRedirect"));
}
 
Example #9
Source File: WebMvcConfigurationSupportExtensionTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("serial")
@Override
public MessageCodesResolver getMessageCodesResolver() {
	return new DefaultMessageCodesResolver() {
		@Override
		public String[] resolveMessageCodes(String errorCode, String objectName) {
			return new String[] { "custom." + errorCode };
		}
	};
}
 
Example #10
Source File: WebMvcConfigurationSupportExtensionTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@SuppressWarnings("serial")
@Override
public MessageCodesResolver getMessageCodesResolver() {
	return new DefaultMessageCodesResolver() {
		@Override
		public String[] resolveMessageCodes(String errorCode, String objectName) {
			return new String[] {"custom." + errorCode};
		}
	};
}
 
Example #11
Source File: AnnotationDrivenBeanDefinitionParserTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testMessageCodesResolver() {
	loadBeanDefinitions("mvc-config-message-codes-resolver.xml");
	RequestMappingHandlerAdapter adapter = this.appContext.getBean(RequestMappingHandlerAdapter.class);
	assertNotNull(adapter);
	Object initializer = adapter.getWebBindingInitializer();
	assertNotNull(initializer);
	MessageCodesResolver resolver =
			((ConfigurableWebBindingInitializer) initializer).getMessageCodesResolver();
	assertNotNull(resolver);
	assertEquals(TestMessageCodesResolver.class, resolver.getClass());
	assertEquals(false, new DirectFieldAccessor(adapter).getPropertyValue("ignoreDefaultModelOnRedirect"));
}
 
Example #12
Source File: WebMvcConfigurerComposite.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public MessageCodesResolver getMessageCodesResolver() {
	MessageCodesResolver selected = null;
	for (WebMvcConfigurer configurer : this.delegates) {
		MessageCodesResolver messageCodesResolver = configurer.getMessageCodesResolver();
		if (messageCodesResolver != null) {
			if (selected != null) {
				throw new IllegalStateException("No unique MessageCodesResolver found: {" +
						selected + ", " + messageCodesResolver + "}");
			}
			selected = messageCodesResolver;
		}
	}
	return selected;
}
 
Example #13
Source File: WebMvcConfigurationSupport.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Return the {@link ConfigurableWebBindingInitializer} to use for
 * initializing all {@link WebDataBinder} instances.
 */
protected ConfigurableWebBindingInitializer getConfigurableWebBindingInitializer() {
	ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
	initializer.setConversionService(mvcConversionService());
	initializer.setValidator(mvcValidator());
	MessageCodesResolver messageCodesResolver = getMessageCodesResolver();
	if (messageCodesResolver != null) {
		initializer.setMessageCodesResolver(messageCodesResolver);
	}
	return initializer;
}
 
Example #14
Source File: WebMvcConfigurerComposite.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public MessageCodesResolver getMessageCodesResolver() {
	List<MessageCodesResolver> candidates = new ArrayList<MessageCodesResolver>();
	for (WebMvcConfigurer configurer : this.delegates) {
		MessageCodesResolver messageCodesResolver = configurer.getMessageCodesResolver();
		if (messageCodesResolver != null) {
			candidates.add(messageCodesResolver);
		}
	}
	return selectSingleInstance(candidates, MessageCodesResolver.class);
}
 
Example #15
Source File: WebMvcConfigurer.java    From tx-lcn with Apache License 2.0 4 votes vote down vote up
@Override
default MessageCodesResolver getMessageCodesResolver() {
    return null;
}
 
Example #16
Source File: WebMvcConfigurerAdapter.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 * <p>This implementation returns {@code null}.
 */
@Override
public MessageCodesResolver getMessageCodesResolver() {
	return null;
}
 
Example #17
Source File: WebMvcConfigurationSupport.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Override this method to provide a custom {@link MessageCodesResolver}.
 */
protected MessageCodesResolver getMessageCodesResolver() {
	return null;
}
 
Example #18
Source File: FilterRegister.java    From jfilter with Apache License 2.0 4 votes vote down vote up
@Override
public MessageCodesResolver getMessageCodesResolver() {
    return null;
}
 
Example #19
Source File: ValidatorConfig.java    From OneBlog with GNU General Public License v3.0 4 votes vote down vote up
@Override
public MessageCodesResolver getMessageCodesResolver() {
    return null;
}
 
Example #20
Source File: WebAdminConfiguration.java    From wallride with Apache License 2.0 4 votes vote down vote up
@Override
public MessageCodesResolver getMessageCodesResolver() {
	return messageCodesResolver;
}
 
Example #21
Source File: DelegatingWebMvcConfiguration.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected MessageCodesResolver getMessageCodesResolver() {
	return this.configurers.getMessageCodesResolver();
}
 
Example #22
Source File: ConfigurableWebBindingInitializer.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return the strategy to use for resolving errors into message codes.
 */
public final MessageCodesResolver getMessageCodesResolver() {
	return this.messageCodesResolver;
}
 
Example #23
Source File: WebConfiguration.java    From servicecomb-pack with Apache License 2.0 4 votes vote down vote up
@Override
public MessageCodesResolver getMessageCodesResolver() {
  //compatible with spring-webmvc 4.x from spring boot 1.x
  return null;
}
 
Example #24
Source File: WxMvcConfiguration.java    From FastBootWeixin with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 * <p>This implementation returns {@code null}.
 */
@Override
public MessageCodesResolver getMessageCodesResolver() {
    return null;
}
 
Example #25
Source File: WebMvcConfigurationSupport.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Override this method to provide a custom {@link MessageCodesResolver}.
 */
protected MessageCodesResolver getMessageCodesResolver() {
	return null;
}
 
Example #26
Source File: WebMvcConfigurerAdapter.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 * <p>This implementation is empty.
 */
@Override
public MessageCodesResolver getMessageCodesResolver() {
	return null;
}
 
Example #27
Source File: DelegatingWebMvcConfiguration.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
protected MessageCodesResolver getMessageCodesResolver() {
	return this.configurers.getMessageCodesResolver();
}
 
Example #28
Source File: ConfigurableWebBindingInitializer.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Return the strategy to use for resolving errors into message codes.
 */
public final MessageCodesResolver getMessageCodesResolver() {
	return this.messageCodesResolver;
}
 
Example #29
Source File: WallRideMessageSourceConfiguration.java    From wallride with Apache License 2.0 4 votes vote down vote up
@Bean
public MessageCodesResolver messageCodesResolver() {
	DefaultMessageCodesResolver resolver = new DefaultMessageCodesResolver();
	resolver.setPrefix("validation.");
	return resolver;
}
 
Example #30
Source File: WallRideWebMvcConfiguration.java    From wallride with Apache License 2.0 4 votes vote down vote up
@Override
public MessageCodesResolver getMessageCodesResolver() {
	return messageCodesResolver;
}