How do I make use of j2htmls each method to add elements of a collection ?
They give an example on https://j2html.com/examples.html
// each() lets you iterate through a collection and returns the generated HTML
// as a DomContent object, meaning you can add siblings, which is not possible
// using the stream api in the previous example
body(
div(attrs("#employees"),
p("Some sibling element"),
each(employees, employee ->
div(attrs(".employee"),
h2(employee.getName()),
img().withSrc(employee.getImgPath()),
p(employee.getTitle())
)
)
)
)
But they don't define what employees or employee actually are.
In my case I want add series of Counter elements to a div (each with label) but I cannot see how to do it, so for now I am only using j2html for each individual counter and then wrapping it with hardcoded tag.
sb.append("<div>\n");
for(Map.Entry<Integer, Counter> next:fsc.getCounters().entrySet())
{
sb.append(label(next.getValue().getText()).attr("for","pb"+next.getKey().intValue()));
sb.append(render(progress()
.withId("pb"+next.getKey().intValue())
.attr("value", next.getValue().getCounter().intValue())
.attr("max", "100")));
sb.append(rendern(br()));
}
sb.append("</div>\n");