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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T13:49:41+00:00 2026-05-16T13:49:41+00:00

I am doing an user crud in spring-mvc. My model has the following properties:

  • 0

I am doing an user crud in spring-mvc.

My model has the following properties:

private Long id;
private String password;
private String username;
private Collection<Authority> myAuthorities;
private boolean isAccountNonExpired;
private boolean isAccountNonLocked;
private boolean isCredentialsNonExpired;
private boolean isEnabled;

I solved how to show the Authority class in this question.

Now I am willing my form to be able to have a second password field to confirm that the user typed the password correctly.

I don’t want to add a confirmPassword property to the model, so my question is how to fix this the best way possible.

Edit:

Everything is working with axtavt’s answer but I am missing a way to validate.
I have the following method in my controller, but even though I place a @Validate
ApplicationUserFormValidator isn’t called.

    @RequestMapping(method = RequestMethod.POST)
 public ModelAndView create(Model model,
   @Valid @ModelAttribute ApplicationUserForm applicationUserFrom,
   BindingResult result) {
  ModelAndView modelAndView = new ModelAndView();

  if (result.hasErrors()) {
   modelAndView.setViewName(USER_CREATE_FORM);
  } else {
   modelAndView.setViewName(REDIRECT_TO_USER_LIST);
   modelAndView.addObject(USER_FORM_MESSAGE, USER_FORM_ADD_SUCCESSFUL);
   applicationUserService.save(applicationUserFrom.getUser);
  }

  return modelAndView;
 }
  • 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-16T13:49:42+00:00Added an answer on May 16, 2026 at 1:49 pm

    You may create an enclosing object to keep a confirmation:

    public class ApplicationUserForm {
        private ApplicationUser user;
        private String confirmPassword;
    
        ...
    }
    

    –

    Password: <form:password path = "user.password" />
    Confirm password: <form:password path = "confirmPassword" />
    

    Validator also works fine:

    public class ApplicationUserFormValidator implements Validator {
        public void validate(Object target, Errors errors) {
            ApplicationUserForm f = (ApplicationUserForm) target;
    
            if (!f.getConfirmPassword().equals(f.getUser().getPassword())) ...
    
            errors.pushNestedPath("user");
            new ApplicationUserValidator().validate(f.getUser(), errors);
            errors.popNestedPath();
        }
        ...
    }
    

    EDIT: If you use @Valid annotation, you need to register a validator using @InitBinder or in the config as described in the docs. You may also use a fully declarative JSR-303-style validation, but i’m not sure how will it play with business constraints such as user.password == confirmPassword.

    @InitBinder
    public void initBinder(WebDataBinder b) {
        b.setValidator(new ApplicationUserFormValidator());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing an simple user crud. My ApplicationUser has the following properties: private
I am learning spring-mvc and I am doing a simple crud. I have a
On a site I'm doing a user can enter a search string like do
I am doing a test to see if the connection string user ID is
So I've got a user model, with login, email address, password, password confirmation, name,
So, I'm doing something like: user.students.includes(:exams).ungraded.paginate(:page => params[:page]).order(exams.created_at desc) However, this causes a subtle
I understand that it is not possible to tell what the user is doing
im doing a little test to check whether the user is away (unactive) or
Simple thing I'm doing is connecting to retrieving user's name from Facebook and passing
I can deny a specific user DB viewing by doing something like this: DENY

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.