Announcement Announcement Module
Collapse
No announcement yet.
Spring validation FieldError default message Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring validation FieldError default message

    After my form backing object is validated I have a BindingResult, which contains a list of FieldError. Each FieldError has a defaultMessage. How is that message set and why doesn't it use my Spring MessageSource?

  • #2
    Any ideas on how to get the default message in the FieldError object to come from my Spring MessageSource? Thanks!

    Comment


    • #3
      Spring validation FieldError default message

      If you are using JSR 303 validation annotation , then you can define messgae source . hope below example will help you ..

      to define message source

      Code:
      @Bean
      	public ResourceBundleMessageSource messageSource(){
      		ResourceBundleMessageSource rs = new ResourceBundleMessageSource();
      		rs.setBasenames("com.american.cst.resource.errorMsg","com.american.cst.resource.label");		
      		return rs;
      	}
      backing bean validation annotation

      Code:
      @NotEmpty
      	@Size(max=40)
      	private String userName ;
      	
      	@NotEmpty
      	@Size(max=40)
      	private String password ;
      property file which contain messages

      Code:
      #login page related messages 
      NotEmpty.userDetail.userName = User Name Should Not Be Empty
      NotEmpty.userDetail.password = Password Should Not Be Empty

      Comment

      Working...
      X