title: How to populate modal window by entity from controller in thymeleaf by ajax query
body: <p>I want to show a particular user with the help of a materialized modal window by clicking on 'view' button. I'm trying to do this by ajax query to my controller. Also I have an error: 
  There was an unexpected error (type=Internal Server Error, status=500).
  Exception evaluating SpringEL expression: "user.firstName" (users:190)</p>
  
  <p>Table:</p>
  
  <pre><code>&lt;tr th:each="user : ${users}"&gt;
              &lt;td th:text="${user.firstName}"&gt;&lt;/td&gt;
              &lt;td th:text="${user.lastName}"&gt;&lt;/td&gt;
              &lt;td th:text="${user.username}"&gt;&lt;/td&gt;
              &lt;td&gt;
                  &lt;a th:onclick="'javascript:viewUser(\'' + ${user.id} +'\');'" class="btn-floating waves-effect waves-light yellow"&gt;&lt;i class="material-icons"&gt;visibility&lt;/i&gt;&lt;/a&gt;
                  &lt;a href="#updateUser" class="btn-floating waves-effect waves-light blue btn modal-trigger"&gt;&lt;i class="material-icons"&gt;edit&lt;/i&gt;&lt;/a&gt;
                  &lt;a th:href="${'/users/delete/' + user.id}" class="btn-floating waves-effect waves-light red"&gt;&lt;i class="material-icons"&gt;delete&lt;/i&gt;&lt;/a&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
  </code></pre>
  
  <p>Modal:</p>
  
  <pre><code>   &lt;div id="viewUser" class="modal modal-fixed-footer" th:fragment="view"&gt;
          &lt;div class="modal-content"&gt;
              &lt;h4&gt;View User&lt;/h4&gt;
                  &lt;div class="row"&gt;
                      &lt;div class="col s12"&gt;
                          &lt;div class="row"&gt;
                              &lt;table&gt;
                                  &lt;thead&gt;
                                  &lt;tr&gt;
                                      &lt;th&gt;&lt;/th&gt;
                                      &lt;th&gt;&lt;/th&gt;
                                  &lt;/tr&gt;
                                  &lt;/thead&gt;
                                  &lt;tbody&gt;
                                  &lt;tr&gt;
                                      &lt;td&gt;First Name: &lt;/td&gt;
                                      &lt;td th:text="${user.firstName}"&gt;&lt;/td&gt;
                                  &lt;/tr&gt;
                                  &lt;tr&gt;
                                      &lt;td&gt;Last Name: &lt;/td&gt;
                                      &lt;td th:text="${user.lastName}"&gt;&lt;/td&gt;
                                  &lt;/tr&gt;
                                  &lt;tr&gt;
                                      &lt;td&gt;Username&lt;/td&gt;
                                      &lt;td th:text="${user.username}"&gt;&lt;/td&gt;
                                  &lt;/tr&gt;
                                  &lt;/tbody&gt;
                              &lt;/table&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="modal-footer"&gt;
              &lt;button class="modal-action modal-close waves-effect waves-light btn-floating red"&gt;&lt;i class="material-icons"&gt;close&lt;/i&gt;&lt;/button&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>JS function:</p>
  
  <pre><code>function viewUser(id) {
      $.ajax({
          url: "/users/view/" + id,
          success: function(response) {
              console.log(response);
              $('#viewUserHolder').html(response);
              $('#viewUser').modal('open');
          }
      });
  }
  </code></pre>
  
  <p>Method in the controller:</p>
  
  <pre><code>@RequestMapping(value = "/view/{id}")
  public String view(@PathVariable("id") Integer id, ModelMap modelMap) {
      User user = userRepository.findOne(id);
      modelMap.addAttribute("user", user);
      return "users :: view";
  }
  </code></pre>