Forms' submit button, inside another form, doesn't seem to go to the mapping, why?












0














My Java/Springboot/Thymeleaf app has a form called direct bind. On this form there is a modal that pops up when you click a button, in this modal you can attach a file. The submit button to the modal, does not seem to be registering or sending to the @Requestmapping. Any idea why and how to fix this?



I've tried setting the controller up like this instead @RequestMapping(value="/attachDoc", params="document"). I've also tried adding formnovalidate="formnovalidate" on the submit input. As well as moving it to the same controller file as the original form. Not sure what else to try.



HTML:



<div id="modal" class="modal" data-izimodal-title="Upload a Document">
<div id="newRequiredDocForm">
<form enctype="multipart/form-data" th:action="@{/attachDoc}" method="post" th:object="${newDocument}">
<div class="row">
<div class="col-xs-4 col-sm-3 text-right"><label class="modalLabel">Type:</label></div>
<div class="col-xs-4 col-sm-3 text-right">
<label class="modalLabel">File:</label>
</div>
<div class="col-xs-8 col-sm-7">
<input type="file" name="document" multiple="multiple" style="margin-right:-20px;"/>
</div>
</div>
<br/><br/>
<div style="text-align: right;"><input type="submit" name="attachNewDoc" value="Submit" class="btn btn-docModal"/></div>
</form>
</div>
</div>


Controller:



@RequestMapping(value="/attachDoc")
public String attachDoc(Model model, @ModelAttribute(value="newDocument") Document newDocument, @RequestParam("document") MultipartFile file){
Document doc=documentRepository.save(newDocument);
doc.setStorage(storageService.store(file));
documentRepository.save(doc);
return "directBind";
}









share|improve this question





























    0














    My Java/Springboot/Thymeleaf app has a form called direct bind. On this form there is a modal that pops up when you click a button, in this modal you can attach a file. The submit button to the modal, does not seem to be registering or sending to the @Requestmapping. Any idea why and how to fix this?



    I've tried setting the controller up like this instead @RequestMapping(value="/attachDoc", params="document"). I've also tried adding formnovalidate="formnovalidate" on the submit input. As well as moving it to the same controller file as the original form. Not sure what else to try.



    HTML:



    <div id="modal" class="modal" data-izimodal-title="Upload a Document">
    <div id="newRequiredDocForm">
    <form enctype="multipart/form-data" th:action="@{/attachDoc}" method="post" th:object="${newDocument}">
    <div class="row">
    <div class="col-xs-4 col-sm-3 text-right"><label class="modalLabel">Type:</label></div>
    <div class="col-xs-4 col-sm-3 text-right">
    <label class="modalLabel">File:</label>
    </div>
    <div class="col-xs-8 col-sm-7">
    <input type="file" name="document" multiple="multiple" style="margin-right:-20px;"/>
    </div>
    </div>
    <br/><br/>
    <div style="text-align: right;"><input type="submit" name="attachNewDoc" value="Submit" class="btn btn-docModal"/></div>
    </form>
    </div>
    </div>


    Controller:



    @RequestMapping(value="/attachDoc")
    public String attachDoc(Model model, @ModelAttribute(value="newDocument") Document newDocument, @RequestParam("document") MultipartFile file){
    Document doc=documentRepository.save(newDocument);
    doc.setStorage(storageService.store(file));
    documentRepository.save(doc);
    return "directBind";
    }









    share|improve this question



























      0












      0








      0







      My Java/Springboot/Thymeleaf app has a form called direct bind. On this form there is a modal that pops up when you click a button, in this modal you can attach a file. The submit button to the modal, does not seem to be registering or sending to the @Requestmapping. Any idea why and how to fix this?



      I've tried setting the controller up like this instead @RequestMapping(value="/attachDoc", params="document"). I've also tried adding formnovalidate="formnovalidate" on the submit input. As well as moving it to the same controller file as the original form. Not sure what else to try.



      HTML:



      <div id="modal" class="modal" data-izimodal-title="Upload a Document">
      <div id="newRequiredDocForm">
      <form enctype="multipart/form-data" th:action="@{/attachDoc}" method="post" th:object="${newDocument}">
      <div class="row">
      <div class="col-xs-4 col-sm-3 text-right"><label class="modalLabel">Type:</label></div>
      <div class="col-xs-4 col-sm-3 text-right">
      <label class="modalLabel">File:</label>
      </div>
      <div class="col-xs-8 col-sm-7">
      <input type="file" name="document" multiple="multiple" style="margin-right:-20px;"/>
      </div>
      </div>
      <br/><br/>
      <div style="text-align: right;"><input type="submit" name="attachNewDoc" value="Submit" class="btn btn-docModal"/></div>
      </form>
      </div>
      </div>


      Controller:



      @RequestMapping(value="/attachDoc")
      public String attachDoc(Model model, @ModelAttribute(value="newDocument") Document newDocument, @RequestParam("document") MultipartFile file){
      Document doc=documentRepository.save(newDocument);
      doc.setStorage(storageService.store(file));
      documentRepository.save(doc);
      return "directBind";
      }









      share|improve this question















      My Java/Springboot/Thymeleaf app has a form called direct bind. On this form there is a modal that pops up when you click a button, in this modal you can attach a file. The submit button to the modal, does not seem to be registering or sending to the @Requestmapping. Any idea why and how to fix this?



      I've tried setting the controller up like this instead @RequestMapping(value="/attachDoc", params="document"). I've also tried adding formnovalidate="formnovalidate" on the submit input. As well as moving it to the same controller file as the original form. Not sure what else to try.



      HTML:



      <div id="modal" class="modal" data-izimodal-title="Upload a Document">
      <div id="newRequiredDocForm">
      <form enctype="multipart/form-data" th:action="@{/attachDoc}" method="post" th:object="${newDocument}">
      <div class="row">
      <div class="col-xs-4 col-sm-3 text-right"><label class="modalLabel">Type:</label></div>
      <div class="col-xs-4 col-sm-3 text-right">
      <label class="modalLabel">File:</label>
      </div>
      <div class="col-xs-8 col-sm-7">
      <input type="file" name="document" multiple="multiple" style="margin-right:-20px;"/>
      </div>
      </div>
      <br/><br/>
      <div style="text-align: right;"><input type="submit" name="attachNewDoc" value="Submit" class="btn btn-docModal"/></div>
      </form>
      </div>
      </div>


      Controller:



      @RequestMapping(value="/attachDoc")
      public String attachDoc(Model model, @ModelAttribute(value="newDocument") Document newDocument, @RequestParam("document") MultipartFile file){
      Document doc=documentRepository.save(newDocument);
      doc.setStorage(storageService.store(file));
      documentRepository.save(doc);
      return "directBind";
      }






      java hibernate spring-boot thymeleaf






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 20 at 17:12









      Jonny Henly

      3,44141839




      3,44141839










      asked Nov 20 at 17:09









      Stacie

      678




      678
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Define method=RequestMethod.POST in your mapping.



          By default if you are not specifying any method in request mapping then it will be GET.



          You are using post method in your thymeleaf but the mapping in the controller is for GET(By default)



          So you have to change requestmapping like below.



          @RequestMapping(value="/attachDoc",method=RequestMethod.POST) by specifying POST method.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53398087%2fforms-submit-button-inside-another-form-doesnt-seem-to-go-to-the-mapping-wh%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Define method=RequestMethod.POST in your mapping.



            By default if you are not specifying any method in request mapping then it will be GET.



            You are using post method in your thymeleaf but the mapping in the controller is for GET(By default)



            So you have to change requestmapping like below.



            @RequestMapping(value="/attachDoc",method=RequestMethod.POST) by specifying POST method.






            share|improve this answer




























              0














              Define method=RequestMethod.POST in your mapping.



              By default if you are not specifying any method in request mapping then it will be GET.



              You are using post method in your thymeleaf but the mapping in the controller is for GET(By default)



              So you have to change requestmapping like below.



              @RequestMapping(value="/attachDoc",method=RequestMethod.POST) by specifying POST method.






              share|improve this answer


























                0












                0








                0






                Define method=RequestMethod.POST in your mapping.



                By default if you are not specifying any method in request mapping then it will be GET.



                You are using post method in your thymeleaf but the mapping in the controller is for GET(By default)



                So you have to change requestmapping like below.



                @RequestMapping(value="/attachDoc",method=RequestMethod.POST) by specifying POST method.






                share|improve this answer














                Define method=RequestMethod.POST in your mapping.



                By default if you are not specifying any method in request mapping then it will be GET.



                You are using post method in your thymeleaf but the mapping in the controller is for GET(By default)



                So you have to change requestmapping like below.



                @RequestMapping(value="/attachDoc",method=RequestMethod.POST) by specifying POST method.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 21 at 6:01

























                answered Nov 20 at 18:17









                Alien

                4,68331024




                4,68331024






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53398087%2fforms-submit-button-inside-another-form-doesnt-seem-to-go-to-the-mapping-wh%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Wiesbaden

                    Marschland

                    Dieringhausen