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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:42:22+00:00 2026-06-18T04:42:22+00:00

Sorry for my dumb question and bad English. i trying to make some validation

  • 0

Sorry for my dumb question and bad English.
i trying to make some validation on user change password menu in my new Developed Web using Spring MVC.

i follow instruction from How to perform Spring validation in MultiActionController?

i write this code :

public ModelAndView hanldeBindException(HttpServletRequest request, HttpServletResponse response, ServletRequestBindingException bindingException) {
    BindException bindException = (BindException) bindingException.getRootCause();
    ModelMap modelmap = new ModelMap();
    ChangePasswordForm cpForm = new ChangePasswordForm();
    cpForm.setUsername(SessionHelper.getUsername());
    modelmap.addAttribute("ChangePasswordForm", cpForm);
    return new ModelAndView("changepassword").addAllObjects(bindException.getModel()).addObject("ChangePasswordForm", cpForm);
}     

and in my jsp :

<form:form action="update.htm" commandName="ChangePasswordForm" >
    <form:errors path="*" cssClass="errorblock" element="div" />
    <table  class="form">
        <tr>
            <td class="col1"><label>User Name :</label></td>
            <td class="col2"><form:label path="username" >${ChangePasswordForm.username}</form:label></td>
        </tr>
        <tr>
            <td><label>Old Password :</label></td>
            <td><form:password path="oldPassword" id="oldPassword"></form:password>
                <form:errors path="oldPassword" cssClass="error" /></td>
        </tr>
        <tr>
            <td><label>New Password :</label></td>
            <td><form:password path="newPassword"></form:password>
            <form:errors path="newPassword" cssClass="error" /></td>
        </tr>
        <tr>
            <td><label>Confirm New Password :</label></td>
            <td><form:password path="confirmNewPassword"></form:password>
            <form:errors path="confirmNewPassword" cssClass="error" /></td>
        </tr>
        <tr>
            <td colspan="2"><input type="submit" value="submit" ></td>
        </tr>
    </table>
</form:form>    

but it does not appear any error on my screen when i try negative test like empty field.
when i try to print out

System.out.println("UserController::hanldeBindException::1" + bindException.getObjectName());

it show the object name is “command” instead of my command name in jsp which is “ChangePasswordForm”. When i try to change that commandName to “command” it works. But i just curious is there some way to setObjectName in BindException Class or you have another way to use custom name instead of default “command” Object Name??

UPDATE

My Validation works since i change commandName to “command” to like this :

<form:form action="update.htm" commandName="command">
   <!-- Form Field and Error define here -->
</form:form>

and of course do some adjustment in my controller also. if i change it to another name it wont work anymore.

I use Spring Framework 3.0.2 RELEASE.

  • 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-06-18T04:42:23+00:00Added an answer on June 18, 2026 at 4:42 am

    simple answer would be that most likely you’re extending BaseCommandController in some form (AbstractCommandController or otherwise), in which case you should probably override the “getCommandName()” and “getCommand()” methods. But i can’t tell from the code you’ve supplied.

    what version of spring are you using? The idea of a “command” is relatively antiquated now as of 3.0+ as are the base classes. Instead use annotation based controllers and model attributes:

    @Controller
    @SessionAttributes({"changePasswordForm"})
    public class MyController {
        @InitBinder
        public void initBinder(WebDataBinder binder) {
           binder.setValidator(new ChangePasswordFormValidator());
        }
    
        @ModelAttribute("changePasswordForm")
        public ChangePasswordForm createChangePasswordForm() {
          ...
        }
    
    
        @RequestMapping(...)
        public ModelAndView controllerMethod(
              @Valid @ModelAttribute changePasswordForm ChangePasswordForm) {
          ...
        }
    }
    

    This should automatically validate your form before calling the controller method, and bounce back to the calling page.

    In your validator, you’ll supply error message code in the validate method:

    public void validate(Object target, Errors errors) {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "username", "username.required");
    }
    

    You would then make sure “username.required” is a key in whatever MessageSource you’ve supplied to spring.

    The form tags should work exactly as you have them.

    Here’s the spring reference manual for controllers:

    http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/mvc.html#mvc-controller

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

Sidebar

Related Questions

I'm new in xml, sorry for the dumb question. I'm trying to create xsl
I am sorry for the dumb question I have been trying for a while
I am new to Cstring, sorry for asking dumb question, please help. char string[10];
sorry for my really dumb question.(I'm so new in this!). I have a query
sorry this is probably a dumb question, but I want to make the background
Sorry for a potentially dumb question, I am still new at this. I really
sorry for the dumb question, but I'm really new to maven and I cannot
I'm new in using lambda expression sorry for a dumb question. Anyway consider this
I'm a newbie here, sorry for the dumb question. I am trying to display
I'm quite new to xcode na objective-c so I'm sorry for the dumb question.

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.