Announcement Announcement Module
Collapse
No announcement yet.
Best way to configer StringTrimmerEditor globally using Spring 3.1 with Java Config Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Best way to configer StringTrimmerEditor globally using Spring 3.1 with Java Config

    What is the best way to configer StringTrimmerEditor globally using Spring 3.1 with Java Config

  • #2
    Hi Marcel, please watch (and comment on if you like) https://jira.springsource.org/browse/SPR-7077

    Comment


    • #3
      Originally posted by marceloverdijk View Post
      What is the best way to configer StringTrimmerEditor globally using Spring 3.1 with Java Config
      With Java Config you can do:
      Code:
      @Configuration
      public class WebConfig extends WebMvcConfigurationSupport {
      
      	@Override
      	public RequestMappingHandlerAdapter requestMappingHandlerAdapter() {
      		RequestMappingHandlerAdapter adapter = super.requestMappingHandlerAdapter();
      		ConfigurableWebBindingInitializer initializer = 
      			(ConfigurableWebBindingInitializer) adapter.getWebBindingInitializer();
      		// Use initializer
      		return adapter;
      	}
      }
      Instead of using @EnableWebMvc, the above config class extends directly from WebMvcConfigurationSupport and overrides the method that creates the RequestMappingHandlerAdapter.

      Comment


      • #4
        This is not working for me

        Originally posted by Rossen Stoyanchev View Post
        With Java Config you can do:
        Code:
        @Configuration
        public class WebConfig extends WebMvcConfigurationSupport {
        
        	@Override
        	public RequestMappingHandlerAdapter requestMappingHandlerAdapter() {
        		RequestMappingHandlerAdapter adapter = super.requestMappingHandlerAdapter();
        		ConfigurableWebBindingInitializer initializer = 
        			(ConfigurableWebBindingInitializer) adapter.getWebBindingInitializer();
        		// Use initializer
        		return adapter;
        	}
        }
        Instead of using @EnableWebMvc, the above config class extends directly from WebMvcConfigurationSupport and overrides the method that creates the RequestMappingHandlerAdapter.
        I added the line:
        Code:
        		// Use initializer
        		initializer.setPropertyEditorRegistrar(new StringTrimmerRegistrar());
        and an private class:
        Code:
        private class StringTrimmerRegistrar implements PropertyEditorRegistrar {
        		@Override
        		public void registerCustomEditors(PropertyEditorRegistry registry) {
        			registry.registerCustomEditor(String.class,
        					new StringTrimmerEditor(true));
        		}
        
        	}
        But the StringTrimmerEditor is not taken into account in controllers...

        Comment

        Working...
        X