title: Hybris form component validation
body: <p>I wrote custom component, which is simple form. After submitting the form, I want to validate the form and in case of error, I want to display them. I tried to make a method with POST request mapping in my class <code>MyFormComponentController extends AbstractAcceleratorCMSComponentController&lt;MyFormComponentModel&gt;</code> but it gets me an error saying that method is not allowed. So I wrote a controller and added action to my form component</p>
  
  <pre><code>@Controller
  @RequestMapping(value = "/action")
  public class MyFormPageController extends AbstractPageController {
  
      @RequestMapping(method = RequestMethod.POST)
      public String doMyPageController(@Valid final MyForm myForm, final BindingResult bindingResult, final Model model)
              return ???; //..in case of error?
  </code></pre>
  
  <p>But when there is an error in my form and I wan't to return is back to the view, only component is displayed. I tried to pass there the value I got from <code>getView()</code> method in my component controller, but it didn't help.</p>
  
  <p>EDIT: I also tried to make form submit with ajax call, like:</p>
  
  <pre><code>$(document).on("submit",'#myForm', function(e){
              e.preventDefault();
              var postData = $("#myForm").serialize();
              var url= $(".js-my-action").data("url");
              $.ajax({
                  url: url,
                  data: JSON.stringify(postData),
                  type: "POST",
                  success: function (response){
                  }
              });
          })
  </code></pre>
  
  <p>and the method which I want to call is</p>
  
  <pre><code>@RequestMapping(value = "/action", method = RequestMethod.POST)
      public String doMyPageController(@RequestBody @Valid final MyForm catalogOrderForm, final Model model) throws IOException, JaloBusinessException, CMSItemNotFoundException {
  </code></pre>
  
  <p>Here I tried to change <code>@RequestBody</code> to <code>@ModelAttribute</code> with a name of the form, but I only get <code>Acces denied (CSRFToken)</code> error:</p>
  
  <pre><code>ERROR [hybrisHTTP24] [SikoAcceleratorAccessDeniedHandler] Access denied happend - org.springframework.security.web.csrf.InvalidCsrfTokenException: Invalid CSRF Token '66d045fd-c9ae-4210-ae97-f2a0e739bcbf"' was found on the request parameter 'CSRFToken' or header 'CSRFToken'.
  </code></pre>
  
  <p>The data which I'm passing in ajax call:</p>
  
  <pre><code>"firstName=Test&amp;lastName=Test&amp;street=Test&amp;city=Test&amp;postalCode=38801&amp;email=test%40test.com&amp;_inspiration=on&amp;_kitchen=on&amp;_door=on&amp;_gdpr=on&amp;CSRFToken=66d045fd-c9ae-4210-ae97-f2a0e739bcbf"
  </code></pre>
  
  <p>Then I tried to pass data in ajax call like:</p>
  
  <pre><code>data: {myForm: postData}
  </code></pre>
  
  <p>but it also didn't work.</p>