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 6991881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:33:44+00:00 2026-05-27T19:33:44+00:00

i am creating a demo application using spring mvc 3.0.I have to apply the

  • 0

i am creating a demo application using spring mvc 3.0.I have to apply the validation over the screen.I searches on the net and found that there is mainly 2 types of validation are used with the application :-

  1. Spring validations using validations Api
  2. Hibernate validation using hibernate validations

Hopefully somebody give me the suggestion which one is good one to implement in the application.

  • 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-27T19:33:44+00:00Added an answer on May 27, 2026 at 7:33 pm

    I used both – I like the Hibernate Validation more – pretty easy to implement and pretty standard. It is automatically enabled when you have an implementation on the classpath. Here is an example:

    @EmailValidator
    @NotBlank
    @Length(max=65)
    private String email; 
    

    Where does the message Error String comes from? In WEB-INF you must have a file called messages.properties :

    NotBlank.ForgotPasswordBackingObject.email=Email address must be present
    

    There is a standard @Email annotation, but an email such as : me@mycompany is considered valid, that is why I had to make my own @EmailValidator(changed a regex flag from * to + in the standard implementation).
    There are some issues that I came across : the order of validation – which validation you want to happen first, this is done with Validation groups, but this are not possible with the @Valid annotation, for example :

    @RequestMapping(method=RequestMethod.POST, value="/auth/changePassword")
    public ModelAndView submitChangePasswordPage(@Valid @ModelAttribute("ChangePasswordBackingObject") ChangePasswordBackingObject backingObject, BindingResult result, Principal principal)
    

    That is why if you have your Controller in this form (in Spring MVC for example), then you have to simulate your logic in a way – I’ve done that also.

    Another cool thing that you can do it to Validate two or more fields at at time (which I found pretty useful):

    @FieldMatch.List({
        @FieldMatch(firstValue = "password" , secondValue = "confirmPassword")
    })
    public class RequestAccountBackingObject implements Serializable {
        private String password;
        private String confirmPassword;
    

    And the implementation :

    @Target({TYPE, ANNOTATION_TYPE})
    @Retention(RUNTIME)
    @Constraint(validatedBy = FieldMatchImpl.class)
    @Documented
    public @interface FieldMatch{
        String message() default "{com.errorMessage}";
        Class<?>[] groups() default {};
        Class<? extends Payload>[] payload() default {};
        String firstValue();
        String secondValue();
        @Target({TYPE, ANNOTATION_TYPE})
        @Retention(RUNTIME)
        @Documented
        @interface List
        { FieldMatch[] value(); }
    }
    

    The other FieldMatchImpl would be :

    public class FieldMatchImpl implements ConstraintValidator<FieldMatch, Object>{
        private String firstFieldName;
        private String secondFieldName;
    

    and you need two methods implemented:

    public void initialize(final FieldMatch constraintAnnotation){
        firstFieldName = constraintAnnotation.firstValue();
        secondFieldName = constraintAnnotation.secondValue();
    

    Also:

    public boolean isValid(final Object value, final ConstraintValidatorContext context){
    
        final String firstObj = BeanUtils.getProperty(value, firstFieldName);
        final String secondObj = BeanUtils.getProperty(value, secondFieldName);
    

    Using org.apache.commons.beanutils.BeanUtils you can now validate the two fields.

    Like this:

    boolean result = firstObj.equals(secondObj);
    if(!result) {
        context.disableDefaultConstraintViolation();
        context.buildConstraintViolationWithTemplate(errorMessage).addNode(firstFieldName).addConstraintViolation();
    }
    

    Other then that it has been a pleasure using the Hibernate Validation so far.

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

Sidebar

Related Questions

I am creating a demo application using Spring mvc 3.0.Now i wants to connect
i am creating media recorder demo application. for that i have take two button
I found one sample application from the Blackberry knowledgebase. From that application I have
I am creating a demo application that randomly selects a venue when a button
I am playing around creating a demo prism application. The application I have has
I am currently creating an application that has a user, the user can follow
I'm creating a new plugin for a jruby on rails application that will eventually
i am creating a demo MVC project and i am getting a Null Object
I'm creating a demo that must be in html code only (no server side
I am using DWR for one of my application. I have setup the environment

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.