Dynamically render content in columns


It is need to render some content in columns often if you know columns count.

writer.startElement("table", this);
writer.writeAttribute("border", "0", null);
writer.writeAttribute("style", "width: 100%;", null);
writer.startElement("tr", this);

int nColCount = 2;
int nRowCount = properties.size() / nColCount;
int nFirstRowCount = nRowCount + (properties.size() - (nRowCount * nColCount));

int nCnt = 0;
boolean isFirstColWrited = false;
for (Entry> entry : properties.entrySet()) {
	if (nCnt == 0) {
		writer.startElement("td", this);
		writer.writeAttribute("valign", "top", null);
	} else {
		if (!isFirstColWrited && nCnt % nFirstRowCount == 0) {
			writer.endElement("td");
			writer.startElement("td", this);
			writer.writeAttribute("valign", "top", null);
			isFirstColWrited = true;
		} else if (isFirstColWrited && nCnt % nRowCount == 0) {
			writer.endElement("td");
			writer.startElement("td", this);
			writer.writeAttribute("valign", "top", null);
		}
	}
	// Payload
	String groupName = entry.getKey();
	List groupProperties = entry.getValue();
	writeGroup(writer, groupName, groupProperties);

	nCnt++;
}

writer.endElement("tr");
writer.endElement("table");

properties.size() – some map with data
writer – javax.faces.context.ResponseWriter