title: Why is the id im getting within this for loop always returning 1? Where as the delete button in the same loop is unique and working properly?
body: <p>thank you first and foremost for offering your help. I am having an issue in this final project for my coding bootcamp. I have a section where users can create job applications they have submitted and create notes for it such as what to prepare for or how the interview went. I have the notes linked with a unique id to the job application and each time a note is created it has a unique id. the edit and the delete buttons are within a loop iterating over the notes and when clicked the Post mappings in the Note Controller take care of the logic and the delete works as it should and grabs the id of the note it is within with the card and deletes it upon click, but when i press the edit button with the same logic the modal it displays always edits only the first note with an id of 1. ive tried moving the form outside of the for loop but then it displays only the last note, never the correct one. What am i missing? Why does it work properly for the delete but not the edit? Attached are the blocks of code for better understanding</p>
  <p>Show page that displays the cards</p>
  <blockquote>
  <pre><code>&lt;!--The loop creating the cards is below. the edit and delete buttons are within with very similar mappings yet the id passed for the edit is always 1--
  </code></pre>
  <blockquote>
  </blockquote>
  <pre><code>    &lt;div class=&quot;card&quot; th:each=&quot;note : ${notes}&quot;&gt;
          &lt;p class=&quot;col-3&quot; th:text=&quot;${#dates.format(note.date, 'dd-MM-yyyy')}&quot;&gt;&lt;/p&gt;
          &lt;h5 class=&quot;col-3&quot; th:text=&quot;${note.title}&quot;&gt;&lt;/h5&gt;
          &lt;p class=&quot;col-6&quot; th:text=&quot;${note.content}&quot;&gt;&lt;/p&gt;
          &lt;!-- BUTTONS--&gt;
          &lt;div class=&quot;d-flex justify-content-end&quot;&gt;
              &lt;form th:action=&quot;@{/notes/{id}/edit/{jobId}(id &gt;=${note.id}, jobId = ${jobApp.getId()})}&quot; method=&quot;post&quot;th:object=&quot;${note}&quot;&gt;
                  &lt;button type=&quot;button&quot; class=&quot;btn btn-sm btn primary m-2&quot; data-bs-toggle=&quot;modal&quot;
                          data-bs-target=&quot;#editNote&quot;&gt;Edit Note
                  &lt;/button&gt;
                  &lt;div th:replace=&quot;/notes/edit.html :: #editNote&quot;&gt;&lt;/div&gt;
              &lt;/form&gt;
              &lt;form th:action=&quot;@{/notes/{id}/delete/{jobId}(id = ${note.id}, jobId = ${jobApp.getId()})}&quot; th:object=&quot;${note}&quot;method=&quot;post&quot;&gt;
                  &lt;button type=&quot;submit&quot; class=&quot;btn btn-sm btn-danger m-2&quot;&gt;Delete Note&lt;/button&gt;
              &lt;/form&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  <p>Edit Page that contains the modal with the post mapping to the notes
  controller</p>
  <pre><code>&lt;!--The edit button opens this modal to allow editing, the title and content in the placeholder for the modal always show the contents of the note with the id of 1--&gt;
  </code></pre>
  
      
          
              
                  
                      Edit Note
                      
                  
                  
                      
                          Title
                          
                      
                      
                          Message:
                          
                      
  <pre><code>            &lt;/div&gt;
              &lt;div class=&quot;modal-footer&quot;&gt;
                  &lt;button type=&quot;button&quot; class=&quot;btn btn-secondary&quot; data-bs-dismiss=&quot;modal&quot;&gt;Close&lt;/button&gt;
                  &lt;button type=&quot;submit&quot; name=&quot;save&quot;&gt;Save changes&lt;/button&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt; &lt;/form&gt;
  </code></pre>
  <p>The NoteController which handles the post mappings. i included the
  delete mapping as well to show the logic and can confirm it does work
  properly</p>
  <pre><code>    @GetMapping(&quot;/notes/{id}/edit/{jobId}&quot;)
  public String editNote (@PathVariable long id, @PathVariable long jobId, Model model){
      model.addAttribute(&quot;jobId&quot;, jobId);
      model.addAttribute(&quot;note&quot;, noteDao.findById(id));
      System.out.println(&quot;the id in the get mapping is &quot; + id);
      return &quot;/notes/edit&quot;;
  }
  
  @PostMapping(&quot;/notes/{id}/edit/{jobId}&quot;)
  public String saveNote (@PathVariable long id, @PathVariable long jobId, @ModelAttribute Note note) {
      System.out.println(&quot;The Id that is being set for the note is &quot; + id);
      note.setId(id);
      note.setJobApplication(jobApplicationDao.findById(jobId));
      note.setDate(Date.from(Instant.now()));
      note.setTitle(note.getTitle());
      note.setContent(note.getContent());
      noteDao.save(note);
      return &quot;redirect:/jobApplications/&quot; + jobId;
  }
  
  @PostMapping(&quot;/notes/{id}/delete/{jobId}&quot;)
  public String deleteNote(@PathVariable long id, @PathVariable long jobId){
      System.out.println(&quot;The ID of the note that is about to be deleted is &quot;+ id);
  
      noteDao.deleteById(id);
      return &quot;redirect:/jobApplications/&quot; + jobId;
  }
  </code></pre>
  </blockquote>
  <p><a href="https://i.stack.imgur.com/QvnZD.png" rel="nofollow noreferrer">Example of the edit modal being used, i clicked the edit button for the second card with an id of 2 but the placeholders are of the note with the id of 1 and when i save it, it changes the first note</a></p>