Reputation: 722
I have this class
public class Cluster {
private int clusterId = -1;
private DataPoint centroid;
private ArrayList<DataPoint> points;
private boolean selected = false;
private float clusterPercentage = -1;
private int clusterValue = -1;
public Cluster(int id, DataPoint centroid) {
...
}
}
And after my clustering algorithm finishes, it creates several clusters which are stored in an ArrayList
like so:
ArrayList<Cluster> my_clusters;
my_clusters.add(new Cluster(...));
And all clusters have some values for their clusterPercentage
and clusterValue
I'm making this interactive. So I've set up a Tomcat Server 8
and display this model in .jsp
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 selected
variable of each cluster.
To do that, I'm iterating over the Cluster ArrayList
and print it.
for (int i = 0; i < km.k; ++i) {
%>
<div class="col-md-4">
<div class="thumbnail">
<div class="caption">
<p><strong>Cluster</strong> <%=cluster_id %>: <%=cluster_size%> points. <br>
Percentage: <%=df4.format(cluster_percentage)%> % <br>
Expressed value: <%=cluster_value %> <br>
Filter test: <%
if (cluster_filter) {
%><strong>PASS</strong><%
}
else {
%>FAIL<%
}
%><br><hr>
Sample: <%=sample_id%><br>
Value: <%=sample_highest_value%><br>
Expr. percentage:
<%
if (sample_highscore >= threshold) {
%><strong><%=df4.format(sample_highscore)%> %</strong><%
}
else {
%><%=df4.format(sample_highscore)%> %<%
}
%>
<div class="checkbox">
<label><input type="checkbox" value="">Option 1</label>
</div>
</div>
</div>
</div>
<%
} %>
So my question is:
Is there a way to dynamically assign id's to my checkbox divs
so that I will be able to know which checkbox was selected? Ofcourse, the div's
will have to match the clusterId
.
Upvotes: 1
Views: 55
Reputation: 681
you can put iterator number which counts the number of check boxes and append it with id(in case id).
String id="cluster";
int iterator=0;
//put itout of your loop
//open loop here
<div class="checkbox" id="<%=id.concat(iterator) %>_div">
iterator++;
// close loop here
i hope it helps you
Upvotes: 0
Reputation: 2621
You can use same cluster_id to create a dynamic id for the div.
<div class="checkbox" id="<%=cluster_id %>_div">
Upvotes: 2