简体   繁体   English

当拒绝值时,form:errors不显示错误消息

[英]form:errors does not display error message when value is rejected

the complete code is in github: https://github.com/cuipengfei/MPJSP/tree/master/tmp 完整的代码在github中: https : //github.com/cuipengfei/MPJSP/tree/master/tmp

in the controller, there is a method that handles the submit: 在控制器中,有一个处理提交的方法:

@RequestMapping(value = "/home", method = RequestMethod.POST)
    public void handleSubmit(Customer model, BindingResult result) {
        System.out.println(model.getUserName());
        result.rejectValue("userName", "required.userName", "user name invalid");
    }

and in jsp, there is a form like this: 在jsp中,有这样的形式:

<form:form method="POST" action="home" modelAttribute="Customer">

    <table>
        <tr>
            <td>Username :</td>
            <td><form:input path="userName" /></td>
            <td><form:errors path="userName" cssClass="error" /></td>
        </tr>
        <tr>
            <td colspan="3"><input type="submit" /></td>
        </tr>
    </table>
</form:form>

the controllers just rejects value every time, but the error message is not displayed. 控制器每次都拒绝值,但不会显示错误消息。

the complete code can be found here: https://github.com/cuipengfei/MPJSP/tree/master/tmp 完整的代码可以在这里找到: https : //github.com/cuipengfei/MPJSP/tree/master/tmp

尝试在表单标签中设置commandName属性

<form:form method="POST" action="home" commandName="Customer">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM