2013-08-05 22 views
0

我遇到了一些問題,使用@Valid和BindingResult不會將錯誤推送到返回的jsp頁面。該方法中的BindingResult,可以正確檢測綁定錯誤,但我目前可以顯示錯誤的唯一方法是手動將result.getAllErrors()添加到頁面。以下元素的無工作:Spring MVC - <form:errors> empty,BindingResult包含錯誤

<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 
@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(); 
    } 

} 

表單域:

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

我已經通過相關BindingResult和錯誤,但大部分現有的問題看沒有工作。

+1

你可以添加更多頁面代碼嗎?例如,「form:form」標籤中的form:errors是否存在? –

+0

@SimonVerhoeven,我現在補充了我的表格的其餘部分。 – Alex

+0

如果出現以下錯誤,請嘗試以下操作:'ModelAndView modelAndView = new ModelAndView(NAMEPAGE); modelAndView.addObject(「dataModel」,dataModel);返回modelAndView;' –

回答

1

通過打開Weblogic 12c控制檯中的樂觀序列化標誌來解決此問題。希望這會幫助其他人。

相關問題