Reputation: 21
I have a data table which contains "Package" objects and 2 columns (packageBarcode and address). I need to add a column (total number of letters in a package), but this value is not in the object. That's why, I used HashMap. I mapped the packageId and totalNumberOfLetters in this HashMap. I want to display this values in dataTable. How can I do this?
<p:column headerText="package"
sortBy="#{package.barcode}"
filterBy="#{package.barcode}"
>
<h:outputText value="#{package.barcode}" />
</p:column>
Upvotes: 2
Views: 3062
Reputation: 1108732
Provided a
private List<Package> packages;
private Map<Long, Integer> totalNumberOfLettersByPackageId;
you can access it as below
<h:dataTable value="#{bean.packages}" var="_package">
<h:column>#{bean.totalNumberOfLettersByPackageId[_package.id]}</h:column>
</h:dataTable>
Do note that I prefixed package
with _
, because package
is a Java literal and a sane EL implementation would throw a runtime exception on that.
Upvotes: 4