Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 978383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:03:00+00:00 2026-05-16T04:03:00+00:00

I am working on simple form to validate fields like this one. public class

  • 0

I am working on simple form to validate fields like this one.

public class Contact {

    @NotNull
    @Max(64)
    @Size(max=64)
    private String name;

    @NotNull
    @Email
    @Size(min=4)
    private String mail;

    @NotNull
    @Size(max=300)
    private String text;


}

I provide getter and setters hibernate dependencies on my classpath also.But i still do not get the how to validate simple form there is actually not so much documentation for spring hibernate combination.

@RequestMapping(value = "/contact", method = RequestMethod.POST)
public String add(@Valid Contact contact, BindingResult result) {
    ....
}

Could you explain it or give some tutorial , except original spring 3.x documentation

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T04:03:01+00:00Added an answer on May 16, 2026 at 4:03 am

    If you want to use the @Valid annotation to trigger the validation of your backing bean. Then it’s not the Hibernate annotation it’s javax.validation.Valid from the validation API.

    To get it running you need both:

    • Hibernate Validator 4.1.0 or higher
      (download it from here: http://sourceforge.net/projects/hibernate/files/hibernate-validator)
    • Bean Validation API
      (download it from here: http://repository.jboss.org/maven2/javax/validation/validation-api/1.0.0.GA/

    In my case I used a custom validator (RegistrationValidator) instead of annotating the form fields in the backing bean to do the validation. I need to set the I18N key’s for the error messages that’s the reason that I had to replace the Spring 3 MessageCodeResolver with my own. The original one from Spring 3 always tries to add type or field name to find the right key when it’s not found in the first way.

    A little example:

    import org.springframework.stereotype.Controller;
    import org.springframework.validation.BindingResult;
    import org.springframework.web.bind.WebDataBinder;
    ...
    import javax.validation.Valid;
    
    @Controller
    public class RegistrationController
    {
        @InitBinder
        protected void initBinder(WebDataBinder binder) 
        {
            binder.setMessageCodesResolver(new MessageCodesResolver());
            binder.setValidator(new RegistrationValidator());
        }
    
        @RequestMapping(value="/userRegistration.html", method = RequestMethod.POST)
        public String processRegistrationForm(@Valid Registration registration, BindingResult result, HttpServletRequest request) 
    {
             if(result.hasErrors())
             {
                return "registration"; // the name of the view
             }
    
             ...
        }
    }
    

    So hope this helps.

    Btw. If someone knows the official webpage of the Bean Validation API, please tell… Thanx.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a simple contact form written in php and have almost
I'm trying to make a simple form, but it's working not so fine. This
Initially this demo application I'm working on had just one page with a simple
I am working on some simple form validation and need some assistance. Basically, I
I have simple php validation form that is halfway working. If you leave the
I am working on a simple news module. There is a form where user
My javascript is not working right. It is simple pre-vailidation form and I can
I'm currently working on a simple form that stores users inputted information to a
I'm trying to write a simple form. The form basically need to validate 2
I have this registration form which is then validated using "bassistance's" validate.js: $('#pForm').validate({ rules:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.