I’m writing a .tagx file, looking to display a listing of objects, in a table, with columns that the user selected.
By the time I get here, I have ${items} that contains my list of database objects, and ${columns} that contains the list of field names that match field names of the ${items} contents.
I’m trying to do:
<table>
<c:forEach var="item" items="${items}" >
<tr>
<c:forEach var="column" items="${columns}">
<td><!-- What should go here? --></td>
</c:forEach>
</tr>
</c:forEach>
</table>
${item.column} gets me a complaint that item has no field named column. Which is true.
Putting ${item.${column}} gives a syntax error (invalid character ‘{‘).
Putting “ASDF” properly shows that the columns are getting laid out good and dummy data gets put in them. So it’s literally everything except accessing an arbitrary field of an item we’re iterating.
Use
${item[column]}. And don’t forget to properly HTML escape using<c:out>.