title: Dynamically assign ids to divs
body: <p>I have this class</p>
  
  <pre><code>public class Cluster {
      private int clusterId = -1;
  
      private DataPoint centroid;
      private ArrayList&lt;DataPoint&gt; points;
  
      private boolean selected = false;
  
  
      private float clusterPercentage = -1;
      private int clusterValue = -1;
  
      public Cluster(int id, DataPoint centroid) {
          ...
      }
  }
  </code></pre>
  
  <p>And after my clustering algorithm finishes, it creates several clusters which are stored in an <code>ArrayList</code> like so:</p>
  
  <pre><code>ArrayList&lt;Cluster&gt; my_clusters;
  my_clusters.add(new Cluster(...));
  </code></pre>
  
  <p>And all clusters have some values for their <code>clusterPercentage</code> and <code>clusterValue</code></p>
  
  <p>I'm making this interactive. So I've set up a <code>Tomcat Server 8</code> and display this model in <code>.jsp</code></p>
  
  <p>What I wan't to do is being able to print out the data that each cluster has calculated and based on that allow the user to change the <code>selected</code> variable of each cluster.</p>
  
  <p>To do that, I'm iterating over the <code>Cluster ArrayList</code> and print it. </p>
  
  <pre><code>for (int i = 0; i &lt; km.k; ++i) {
          %&gt;
                  &lt;div class="col-md-4"&gt;
                      &lt;div class="thumbnail"&gt;
                          &lt;div class="caption"&gt;
                              &lt;p&gt;&lt;strong&gt;Cluster&lt;/strong&gt; &lt;%=cluster_id %&gt;: &lt;%=cluster_size%&gt; points. &lt;br&gt;
                              Percentage: &lt;%=df4.format(cluster_percentage)%&gt; % &lt;br&gt;
                              Expressed value: &lt;%=cluster_value %&gt; &lt;br&gt;
                              Filter test: &lt;%
                              if (cluster_filter) {
                                  %&gt;&lt;strong&gt;PASS&lt;/strong&gt;&lt;%
                              }
                              else {
                                  %&gt;FAIL&lt;%
                              }
                              %&gt;&lt;br&gt;&lt;hr&gt;
                              Sample: &lt;%=sample_id%&gt;&lt;br&gt;
                              Value: &lt;%=sample_highest_value%&gt;&lt;br&gt;
                              Expr. percentage: 
                              &lt;%
                              if (sample_highscore &gt;= threshold) {
                                  %&gt;&lt;strong&gt;&lt;%=df4.format(sample_highscore)%&gt; %&lt;/strong&gt;&lt;%
                              }
                              else {
                                  %&gt;&lt;%=df4.format(sample_highscore)%&gt; %&lt;%
                              }
                              %&gt;
                              &lt;div class="checkbox"&gt;
                                &lt;label&gt;&lt;input type="checkbox" value=""&gt;Option 1&lt;/label&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;%
          } %&gt;
  </code></pre>
  
  <p>So my question is: </p>
  
  <p>Is there a way to dynamically assign id's to my <code>checkbox divs</code> so that I will be able to know which checkbox was selected? Ofcourse, the <code>div's</code> will have to match the <code>clusterId</code>. </p>