title: Access to a model attribute in Javascript with Spring MVC
body: <p><a href="https://i.stack.imgur.com/41yEY.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/41yEY.jpg" alt="Console output"></a></p>
  
  <p>I have some problem accessing to model attribute in Javascript; in particular I have this controller:</p>
  
  <pre><code>    @RequestMapping(value = "/dashboard")
      public ModelAndView home(HttpServletRequest request, HttpServletResponse 
      res, Model model) {
          // Return answer's dictionary from DB to dashboard view
          CompQuest dizRisp = new CompQuest();
          dizRisp.setDizComp(dashDao.getRispEnd());
          model.addAttribute("dizRisp", dizRisp);
  
          return new ModelAndView("dashboard");    
      }
  </code></pre>
  
  <p>and I have this Javascript file (here: only the part with the code for my chart where I want to refer to model attribute) where I want to access to model attribute "dizRisp" from my controller:</p>
  
  <pre><code>var ctx1 = document.getElementById('myChart1').getContext('2d');
  var myRadarChart = new Chart(ctx1, {
      type: 'radar',
      data: {
          labels: ['Valori e identità del SCN', 'La cittadinanza attiva',
                'Il giovane volontario nel sistema del SC', 'Lavorare',
                'Prevenzione e protezione', 'Normativa sicurezza',
                'Rischi sulla salute in tema di ambiente'
          ],
          datasets: [{
              label: "Civiche",
              data: [4, 5, 5, 2, 4, 5, 4],
              fill: true,
              borderJoinStyle: "round"
          }],
      },
      options: {
          maintainAspectRatio: false,
          scale: {
              ticks: {
                  stepSize: 1,
                  step: 1,
                  beginAtZero: true,
                  max: 5
              }
          }
      }
  });
  </code></pre>
  
  <p>My classes are (here: no getters and setters):</p>
  
  <pre><code>public class CompQuest {
  private HashMap &lt;String, CompRisp&gt; dizComp;}
  
  public class CompRisp {
  private ArrayList &lt;Risposte&gt; rispList = new ArrayList &lt;Risposte&gt; ();}
  
  public class Risposte {
  int id;
  Domande domande;
  int valore;
  int momento; }
  
  public class Domande {
  int id;
  String testo;
  String descrizione;
  Questionario questionario; }
  </code></pre>
  
  <p>My .jsp file:
  
  </p>
  
  <p></p>
  
  <pre><code>&lt;meta charset="UTF-8"&gt;
  
  &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.min.js" &gt;&lt;/script&gt;
  &lt;script src="resources/dashboard.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;link rel="stylesheet" href="${pageContext.request.contextPath}/resources/dashboard.css"&gt;
  &lt;title&gt;Dashboard&lt;/title&gt;
  &lt;style&gt;
      @import url('https://fonts.googleapis.com/css?family=Bitter|Roboto+Condensed');
      @import url('https://fonts.googleapis.com/css?family=Roboto');
  &lt;/style&gt;
  </code></pre>
  
  <p></p>
  
  <p>In particular I would want to access to my model attribute (Hashmap) in order to put in label and datasets field of my Javascript chart values from my Hashmap that contains data from my Database.</p>
  
  <p>Thanks in advance to everyone that can help me!</p>