DisplayTag indexing ?
-
28-04-2021 - |
Question
How do I get the index location in DisplayTag lib ?
I've been trying the following but appreantly it's not right:
<display:table name="${actionBean.templateItems}" id="templateItems" defaultsort="">
<display:column title="Product" property="name"/>
<stripes:hidden name="templateItems[%{#attr.row_rowNum - 1}].id" value="${templateItems.id}"/>
</display:table>
Solution
displaytag uses the id attribute of the table tag, and appends "_rowNum" to this attribute, to define another attribute containing the current row number.
So, the attribute, in your case, is named templateItems_rowNum
. And as any page scope attribute, you access it using ${templateItems_rowNum}
:
<stripes:hidden name="templateItems[${templateItems_rowNum - 1}].id"
value="${templateItems.id}" />
You shouldn't use a plural form (templateItems
) to refer to a single object. It makes things very confusing. The current element should thus be named templateItem
.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow