弹簧形式:错误不会渲染

时间:2015-02-27 15:41:44

标签: java validation jsp spring-mvc spring-form

我有fiollowing控制器方法:

    @RequestMapping(value = "/admin/addNewAdmin")
    public String adminUsers(@ModelAttribute @Valid TerminalAdmin newAdmin, BindingResult bindingResult, ModelMap model, Principal principal, HttpSession session) {
        if (bindingResult.hasErrors()) {
            ...
            model.addAttribute("newAdmin",newAdmin);            
            return "admin/adminUsers";          
        }
        ....
    }

以下型号:

Entity
@Table(name = "terminal_admin")
public class TerminalAdmin {

    .....

    @Column(name = "email", nullable = false)
    @Size(max = 255)
    @NotEmpty
    private String email;

}

JSP:

    <form:form modelAttribute="newAdmin" action="/admin/addNewAdmin">
            <div class="line">
                <label for="">email</label>
                <form:input path="email" type="text" name="emal" value=""/>
                !!!<form:errors path="email" cssClass="error"/>!!!
                <div class="clear"></div>
            </div>
    </form:form>

我将空电子邮件输入表格

在控制器方法的调试中,我发现bindingResult有错误,电子邮件不应为空。

jsp呈现为:

<form id="newAdmin" action="/admin/addNewAdmin" method="post">
            <div class="line">
                <label for="">email</label>
                <input id="email" name="email" type="text" value="">
                !!!!!!
                <div class="clear"></div>
            </div>
</form>

1 个答案:

答案 0 :(得分:0)

替换后工作

newAdmin

terminalAdmin

https://stackoverflow.com/a/2912049/2674303

的第二点