Ayyoub
Ayyoub

Reputation: 1375

JSP doesn't display validation errors

<spring:bind path="aDepartment">
                <div class="form-group ${status.error ? 'has-error' : ''}">
                    <label class="col-lg-4 control-label">Department  *</label>
                    <div class="col-lg-8">
                    <form:input class="form-control" path="aDepartment" required="true"
                        placeholder="Department" />
                    <form:errors path="aDepartment" class="control-label" />
                    </div>
                </div>
</spring:bind> 

PATH is the path of the current page. When I violate validation rules (on purpose) , errors are not bound to the model and the jsp doesn't display the errors. Should I bind the errors manually to the model ? If so how can I do it ?

@RequestMapping(value = "/admin/adepartement/add", method = RequestMethod.POST)
    public String add(
            @ModelAttribute(value = "addadepartment") @Valid ADepartment pADepartment,
            final BindingResult pBindingResult, final ModelMap pModel) {
        if (!pBindingResult.hasErrors()) {
            ///
            }
        }else{
            return PATH;
        }
    } 

Upvotes: 1

Views: 43

Answers (1)

Elmehdi93
Elmehdi93

Reputation: 70

It should work just fine ! Make sure that "aDepartment" in the path refers to an attribute called "aDepartment" in your "ADepartment" Class.

Upvotes: 1

Related Questions