Alex
Alex

Reputation: 5636

Spring MVC - <form:errors> empty, BindingResult contains errors

I am experiencing some issues with @Valid and BindingResult not pushing errors to the returned jsp page. The BindingResult in the method, detects binding errors correctly but the only way I can currently display errors is by manually adding result.getAllErrors() to the page. None of the following elements work:

<form:form name="updateForm" commandName="dataModel" method="post" action="${pageContext.request.contextPath}/pages/data">

    <form:errors path="*" />
    <form:errors />


    <c:forEach items="${dataModel.rows}" var="data" varStatus="currRow">
        <c:out value="${data.code}" />
        <form:errors path="dataRows[${currRow.index}].tolPercentage" />
        <form:input path="dataRows[${currRow.index}].tolPercentage" />
    </c:forEach>

</form:form>

Controller class method:

@Controller
@SessionAttributes("dataModel")
public class DataControllerController{

    @RequestMapping(value = "/data", method = RequestMethod.POST)
    protected ModelAndView onSubmit(
            @ModelAttribute("dataModel") @Valid DataModel dataModel ,
            BindingResult result
    ) throws ServletException, IOException {

        ModelAndView model = new ModelAndView("DataFormPage");

        if ( result.hasErrors() ) {
            model.addAllObjects(result.getModel());
        } else {
            ...
        }

        return model;
    }

    @ModelAttribute("dataModel")
    public DataModel getDataModel() {
        return new DataModel();
    }

}

Form field:

@Min(0)
@Max(1)
@Digits(fraction=2, integer = 1)
@Column(name="TOL_PERCENTAGE", precision = 1, scale = 2)
private BigDecimal tolPercentage;

I have looked through the majority of existing questions related to BindingResult and errors but none have worked.

Upvotes: 0

Views: 3565

Answers (1)

Alex
Alex

Reputation: 5636

Managed to fix this problem by switching on the Optimistic Serialization flag in the Weblogic 12c Console. Hope this will help others.

Upvotes: 1

Related Questions