title: Thymeleaf: Show a success message after clicking on submit button
body: <p>I have a <code>spring-boot</code> application, with <code>Thymeleaf</code>. I have pretty basic scenario. There is a form, and when the user clicks on the submit button, the forms data should be sent to the to the controller, but <strong>in the same page a success message should shows up.</strong></p>
  
  <p>The form is pretty simple:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;form th:action="@{/suggest-event}"  method="post"&gt;
      &lt;button type="submit" class="btn btn-primary"&gt;Submit&lt;/button&gt;
  &lt;/form&gt;
  &lt;div th:switch="${message}"&gt;
      &lt;div th:case="'Success'" class="alert alert-success"&gt;
          &lt;strong&gt;Success!&lt;/strong&gt; Operation performed successfully.
      &lt;/div&gt;
      &lt;div th:case="'Failed'" class="alert alert-danger"&gt;
          &lt;strong&gt;Failure!&lt;/strong&gt; Operation failed. Please try again 
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>To load the form I used the below method in controller:</p>
  
  
  
  <pre class="lang-java prettyprint-override"><code>@GetMapping("/suggest-event")
  public String suggestEvent(@RequestParam(value = "message", required = false) String message) {
  
      model.addAttribute("message",message);
      return "/suggested-event/suggestEvent";
  }
  </code></pre>
  
  <p>and then the method to answer the post request:</p>
  
  <pre class="lang-java prettyprint-override"><code>@PostMapping("/suggest-event")
  public String receiveSuggestedEvent( RedirectAttributes redirectAttributes) {
  
      redirectAttributes.addAttribute("message", "Success");
      return "redirect:/suggest-event";
  }
  </code></pre>
  
  <p>The problem is, the success message is always there (when the page loads for the first time, and before I submit the form). How can I fix it?</p>