Results 1 to 3 of 3

Thread: Spring validation FieldError default message

Hybrid View

  1. #1

    Default 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. #2

    Default

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

  3. #3
    Join Date
    Jun 2012
    Posts
    6

    Default 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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •