无法以弹簧形式获取错误消息

时间:2015-01-14 05:09:30

标签: spring spring-mvc

我正在考虑使用实体Department的CURD操作的Spring Web应用程序,这是处理新Department的提交的处理程序:

@RequestMapping(value = "/", method = RequestMethod.POST)
public String addSubmit(@Valid Department department, BindingResult result,SessionStatus status) {
    if (result.hasErrors()) {
        return "department/add";
    } else {
        departmentService.save(department);
        status.setComplete();
        return "redirect:/departments/" + department.getId();
    }
}

型号:

@Entity
public class Department extends BaseNamedEntity {
    @NotNull
    @NotEmpty
    private String description;
    ...
}

形式:

<form:form method="post" action="${fmURL}" class="form-horizontal" commandName="department">
    <form:hidden path="id"/>
    <spring:bind path="name">
        <div class="control-group ${status.error ? 'error' : ''}">
            <label class="control-label">Name</label>
            <div class="controls">
                <form:input path="name"/>
                <span class="help-inline">${status.errorMessage}</span>
            </div>
        </div>
    </spring:bind>
<form:form>

但是,一旦我提交带有空字段的表单,通常应该显示errorMessage,相关的div应该添加一个error的类,但是我找不到错误消息。

发生了什么?

顺便说一下,这个例子来自Spring-petclinic project

0 个答案:

没有答案