I need to show images dynamically in a data table column, I have the images in a local folder, how can I do that in Bootsfaces data table?
Thanks for any help!
I need to show images dynamically in a data table column, I have the images in a local folder, how can I do that in Bootsfaces data table?
Thanks for any help!
Simply nesting an HTML img
tag in a b:dataTableColumn
does the trick:
<b:dataTable value="#{carPool.carPool}" var="car" class="editableCarTable">
<b:dataTableColumn value="#{car.brand}" />
<b:dataTableColumn label="Image">
<img src="https://www.example.com/some.png" />
</b:dataTableColumn>
</b:dataTable>
You've mentioned the images are stored in a local folder. You'll have to make these images accessible to the web server. Usually, I do so by copying the images to src/main/webapp/images
. Once the images are there, they've got a URL, so you can display them using this URL.
To make the image row-specific, put the URL into the row bean, so you can access it like so:
<b:dataTable value="#{carPool.carPool}" var="car" class="editableCarTable">
<b:dataTableColumn value="#{car.brand}" />
<b:dataTableColumn label="Image">
<img src="#{car.rowSpecificURL()}" />
</b:dataTableColumn>
</b:dataTable>
Of course, you can also use h:graphicImage
or b:image
. Both allow you to benefit from the resources folder Mitch mentioned above in the comment. The BootsFaces b:image
also supports things like tooltips, a progress bar, and so on.