Note that there are some explanatory texts on larger screens.

plurals
  1. PO@ModelAttribute and BindingResult behavior
    primarykey
    data
    text
    <p>I have created two classes A and B. Class A has a method calculate </p> <pre><code>@RequestMapping(method = RequestMethod.POST) public String calculate( HttpServletRequest request, PlanVO planVO, BindingResult result, Map&lt;String, Object&gt; model) throws ParserConfigurationException, SAXException, IOException { validator.validate(planVO, result); if (result.hasErrors()) { model.put(PLAN_VO, planVO); return "test"; } </code></pre> <p>Class B also has the same method with same parameters as shown below</p> <pre><code>@RequestMapping(method = RequestMethod.POST) public String calculate( HttpServletRequest request, PlanVO planVO, BindingResult result, Map&lt;String, Object&gt; model) throws ParserConfigurationException, SAXException, IOException { validator.validate(planVO, result); if (result.hasErrors()) { model.put(PLAN_VO, planVO); return "test"; } </code></pre> <p>When I am running the code, class A validates the inputs and test.jsp is opened. On test.jsp errors are being displayed using <code>&lt;spring:errors path="*"/&gt;</code>. </p> <p>If i do the same for class B, it validates the input populate the BindingResult object and response goes to test.jsp. but I am not able to see the errors.</p> <p>Also if I update the method signature in class B as <code>@modelAttribute("planVO") PlanVO planVO,</code> it starts working as shown below.</p> <pre><code>@RequestMapping(method = RequestMethod.POST) public String calculate( HttpServletRequest request, @ModelAttribute("planVO") PlanVO planVO, BindingResult result, Map&lt;String, Object&gt; model) throws ParserConfigurationException, SAXException, IOException { validator.validate(planVO, result); if (result.hasErrors()) { model.put(PLAN_VO, planVO); return "test"; } </code></pre> <p>Now I want to ask why class A is not asking for this @ModelAttribute or why class B is asking for this?</p> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload