0

I am trying to call a method that returns a model and prints out a simple message to the console using Thymeleaf. However, I realize that whenever I setup the action to be called it does not work the way I want it to. The function does not get called. Though when I go into view page source and click the button it does the desired action. I have tried to use th:action instead but still get the same issue of it not getting the model and not doing the System.out.print("Works") line of code. I have been stuck so long on this issue and have read some documentation, but I can't seem to figure out a way to solve it.

HTML:


    <div class="modal-footer">
            <a th:href="@{/mqlGetSecondQuery}" class="selectorBtn">
                  <button type="button" class="btn btn-primary modalPathContentBtn" 
                   data-dismiss="modal">Continue</button>
            </a>
    </div>

Java:

@RequestMapping(value = "/mqlGetSecondQuery", method = RequestMethod.GET)
    public void getMQLSecondQuery(Model model) {

         model.addAttribute("queryResult", stringFromClass);
         System.out.println("Works");
    }
kane_004
  • 253
  • 3
  • 18
  • It is not quite clear what you are attempting to do.. Are you trying to call the the method from another class, and in this case doesn't work? Btw, the method does not return any model, it just adds an attribute. – Fabio Piunti Jan 09 '20 at 15:53
  • @FabioPiunti So in my HTML, I have it setup that when you press a certain button, it should link and run the method associated with it in my Java controller. – kane_004 Jan 09 '20 at 15:56
  • So, when does it work? What do you mean with "hough when I go into view page source and click the button it does the desired action?". Do you men the actual source page with chrome? – Fabio Piunti Jan 09 '20 at 15:59
  • @FabioPiunti So yes, only when I go to the view page source in chrome, and then click on the link does it work. Other than that it does not work, when I click the button. – kane_004 Jan 09 '20 at 16:05

1 Answers1

0

You have <button> element inside <a> element, meaning you have 2 clickable elements in the same place. Basically it is not valid HTML syntax. I suspect this could mess up with triggering an action.

Please remove

<button type="button" class="btn btn-primary modalPathContentBtn" 
                   data-dismiss="modal">Continue</button>

from your view and provide any valid content instead (e.g. plain text Continue).

Jakub Ch.
  • 3,577
  • 3
  • 24
  • 43