Java 类org.springframework.validation.MessageCodesResolver 实例源码

项目:eHMP    文件:JsonCErrorTests.java   
@Test
public void testConstructFromSpringErrors() {
    MessageCodesResolver mockMessageCodesResolver = mock(MessageCodesResolver.class);
    when(mockMessageCodesResolver.resolveMessageCodes("default.blank.message", "foo", "bar", null)).thenReturn(new String[] {"Property [bar] cannot be blank"});
    when(mockMessageCodesResolver.resolveMessageCodes("default.blank.message", "foo", "baz", null)).thenReturn(new String[] {"Property [baz] cannot be blank"});

    MapBindingResult errors = new MapBindingResult(new HashMap(), "foo");
    errors.setMessageCodesResolver(mockMessageCodesResolver);
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "bar", "default.blank.message");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "baz", "default.blank.message");

    JsonCError jsonc = new JsonCError(errors);

    assertThat(jsonc.getCode(), is("Property [bar] cannot be blank"));
    assertThat(jsonc.getMessage(), is("Field error in object 'foo' on field 'bar': rejected value [null]; codes [Property [bar] cannot be blank]; arguments []; default message [null]"));

    List<Map<String,Object>> errorList = jsonc.getErrors();
    assertThat((String) errorList.get(0).get("code"), is("Property [bar] cannot be blank"));
    assertThat((String) errorList.get(0).get("message"), is("Field error in object 'foo' on field 'bar': rejected value [null]; codes [Property [bar] cannot be blank]; arguments []; default message [null]"));
    assertThat((String) errorList.get(1).get("code"), is("Property [baz] cannot be blank"));
    assertThat((String) errorList.get(1).get("message"), is("Field error in object 'foo' on field 'baz': rejected value [null]; codes [Property [baz] cannot be blank]; arguments []; default message [null]"));
}
项目:class-guard    文件:WebMvcConfigurerComposite.java   
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);
}
项目:spring4-understanding    文件:WebMvcConfigurerComposite.java   
@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);
}
项目:spring4-understanding    文件:WebMvcConfigurationSupportExtensionTests.java   
@SuppressWarnings("serial")
@Override
public MessageCodesResolver getMessageCodesResolver() {
    return new DefaultMessageCodesResolver() {
        @Override
        public String[] resolveMessageCodes(String errorCode, String objectName) {
            return new String[] { "custom." + errorCode };
        }
    };
}
项目:spring4-understanding    文件:AnnotationDrivenBeanDefinitionParserTests.java   
@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"));
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:WebMvcAutoConfiguration.java   
@Override
public MessageCodesResolver getMessageCodesResolver() {
    if (this.mvcProperties.getMessageCodesResolverFormat() != null) {
        DefaultMessageCodesResolver resolver = new DefaultMessageCodesResolver();
        resolver.setMessageCodeFormatter(
                this.mvcProperties.getMessageCodesResolverFormat());
        return resolver;
    }
    return null;
}
项目:spring-boot-concourse    文件:WebMvcAutoConfiguration.java   
@Override
public MessageCodesResolver getMessageCodesResolver() {
    if (this.mvcProperties.getMessageCodesResolverFormat() != null) {
        DefaultMessageCodesResolver resolver = new DefaultMessageCodesResolver();
        resolver.setMessageCodeFormatter(
                this.mvcProperties.getMessageCodesResolverFormat());
        return resolver;
    }
    return null;
}
项目:contestparser    文件:WebMvcAutoConfiguration.java   
@Override
public MessageCodesResolver getMessageCodesResolver() {
    if (this.mvcProperties.getMessageCodesResolverFormat() != null) {
        DefaultMessageCodesResolver resolver = new DefaultMessageCodesResolver();
        resolver.setMessageCodeFormatter(
                this.mvcProperties.getMessageCodesResolverFormat());
        return resolver;
    }
    return null;
}
项目:class-guard    文件:WebMvcConfigurationSupportExtensionTests.java   
@SuppressWarnings("serial")
@Override
public MessageCodesResolver getMessageCodesResolver() {
    return new DefaultMessageCodesResolver() {
        @Override
        public String[] resolveMessageCodes(String errorCode, String objectName) {
            return new String[] { "custom." + errorCode };
        }
    };
}
项目:class-guard    文件:AnnotationDrivenBeanDefinitionParserTests.java   
@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"));
}
项目:lams    文件:ConfigurableWebBindingInitializer.java   
/**
 * Return the strategy to use for resolving errors into message codes.
 */
public final MessageCodesResolver getMessageCodesResolver() {
    return this.messageCodesResolver;
}
项目:miaohu    文件:WebConfig.java   
@Override
public MessageCodesResolver getMessageCodesResolver() {
    return null;
}
项目:spring4-understanding    文件:WebMvcConfigurationSupport.java   
/**
 * Override this method to provide a custom {@link MessageCodesResolver}.
 */
protected MessageCodesResolver getMessageCodesResolver() {
    return null;
}
项目:spring4-understanding    文件:WebMvcConfigurerAdapter.java   
/**
 * {@inheritDoc}
 * <p>This implementation is empty.
 */
@Override
public MessageCodesResolver getMessageCodesResolver() {
    return null;
}
项目:spring4-understanding    文件:DelegatingWebMvcConfiguration.java   
@Override
protected MessageCodesResolver getMessageCodesResolver() {
    return this.configurers.getMessageCodesResolver();
}
项目:spring4-understanding    文件:ConfigurableWebBindingInitializer.java   
/**
 * Return the strategy to use for resolving errors into message codes.
 */
public final MessageCodesResolver getMessageCodesResolver() {
    return this.messageCodesResolver;
}
项目:openmrs-module-legacyui    文件:BaseCommandController.java   
/**
 * Return the strategy to use for resolving errors into message codes (if any).
 */
public final MessageCodesResolver getMessageCodesResolver() {
    return this.messageCodesResolver;
}
项目:class-guard    文件:BaseCommandController.java   
/**
 * Return the strategy to use for resolving errors into message codes (if any).
 */
public final MessageCodesResolver getMessageCodesResolver() {
    return this.messageCodesResolver;
}
项目:class-guard    文件:BaseCommandController.java   
/**
 * Return the strategy to use for resolving errors into message codes (if any).
 */
public final MessageCodesResolver getMessageCodesResolver() {
    return this.messageCodesResolver;
}
项目:class-guard    文件:WebMvcConfigurationSupport.java   
/**
 * Override this method to provide a custom {@link MessageCodesResolver}.
 */
protected MessageCodesResolver getMessageCodesResolver() {
    return null;
}
项目:class-guard    文件:DelegatingWebMvcConfiguration.java   
@Override
protected MessageCodesResolver getMessageCodesResolver() {
    return this.configurers.getMessageCodesResolver();
}
项目:class-guard    文件:ConfigurableWebBindingInitializer.java   
/**
 * Return the strategy to use for resolving errors into message codes.
 */
public final MessageCodesResolver getMessageCodesResolver() {
    return this.messageCodesResolver;
}
项目:spring-rythm    文件:RythmConfigurer.java   
@Override
public MessageCodesResolver getMessageCodesResolver() {
    return null;
}
项目:lams    文件:ConfigurableWebBindingInitializer.java   
/**
 * Set the strategy to use for resolving errors into message codes.
 * Applies the given strategy to all data binders used by this controller.
 * <p>Default is {@code null}, i.e. using the default strategy of
 * the data binder.
 * @see org.springframework.validation.DataBinder#setMessageCodesResolver
 */
public final void setMessageCodesResolver(MessageCodesResolver messageCodesResolver) {
    this.messageCodesResolver = messageCodesResolver;
}
项目:spring4-understanding    文件:WebMvcConfigurer.java   
/**
 * Provide a custom {@link MessageCodesResolver} for building message codes
 * from data binding and validation error codes. Leave the return value as
 * {@code null} to keep the default.
 */
MessageCodesResolver getMessageCodesResolver();
项目:spring4-understanding    文件:ConfigurableWebBindingInitializer.java   
/**
 * Set the strategy to use for resolving errors into message codes.
 * Applies the given strategy to all data binders used by this controller.
 * <p>Default is {@code null}, i.e. using the default strategy of
 * the data binder.
 * @see org.springframework.validation.DataBinder#setMessageCodesResolver
 */
public final void setMessageCodesResolver(MessageCodesResolver messageCodesResolver) {
    this.messageCodesResolver = messageCodesResolver;
}
项目:openmrs-module-legacyui    文件:BaseCommandController.java   
/**
 * Set the strategy to use for resolving errors into message codes.
 * Applies the given strategy to all data binders used by this controller.
 * <p>Default is {@code null}, i.e. using the default strategy of
 * the data binder.
 * @see #createBinder
 * @see org.springframework.validation.DataBinder#setMessageCodesResolver
 */
public final void setMessageCodesResolver(MessageCodesResolver messageCodesResolver) {
    this.messageCodesResolver = messageCodesResolver;
}
项目:class-guard    文件:BaseCommandController.java   
/**
 * Set the strategy to use for resolving errors into message codes.
 * Applies the given strategy to all data binders used by this controller.
 * <p>Default is {@code null}, i.e. using the default strategy of the data binder.
 * @see #createBinder
 * @see org.springframework.validation.DataBinder#setMessageCodesResolver
 */
public final void setMessageCodesResolver(MessageCodesResolver messageCodesResolver) {
    this.messageCodesResolver = messageCodesResolver;
}
项目:class-guard    文件:BaseCommandController.java   
/**
 * Set the strategy to use for resolving errors into message codes.
 * Applies the given strategy to all data binders used by this controller.
 * <p>Default is {@code null}, i.e. using the default strategy of
 * the data binder.
 * @see #createBinder
 * @see org.springframework.validation.DataBinder#setMessageCodesResolver
 */
public final void setMessageCodesResolver(MessageCodesResolver messageCodesResolver) {
    this.messageCodesResolver = messageCodesResolver;
}
项目:class-guard    文件:WebMvcConfigurer.java   
/**
 * Provide a custom {@link MessageCodesResolver} for building message codes
 * from data binding and validation error codes. Leave the return value as
 * {@code null} to keep the default.
 */
MessageCodesResolver getMessageCodesResolver();
项目:class-guard    文件:WebMvcConfigurerAdapter.java   
/**
 * {@inheritDoc}
 * <p>This implementation is empty.
 */
public MessageCodesResolver getMessageCodesResolver() {
    return null;
}
项目:class-guard    文件:ConfigurableWebBindingInitializer.java   
/**
 * Set the strategy to use for resolving errors into message codes.
 * Applies the given strategy to all data binders used by this controller.
 * <p>Default is {@code null}, i.e. using the default strategy of
 * the data binder.
 * @see org.springframework.validation.DataBinder#setMessageCodesResolver
 */
public final void setMessageCodesResolver(MessageCodesResolver messageCodesResolver) {
    this.messageCodesResolver = messageCodesResolver;
}