I'm displaying images on <p:graphicImage>
which are stored under the webroot\resources\fileUpload\product_image\thumb
directory as follows.
<p:graphicImage library="fileUpload"
name="#{not empty row.prodImage?'product_image/thumb/':' '}#{row.prodImage}"
alt="#{row.prodName}"/>
row
refers to a JPA entity object stored in a java.util.List<Entity>
which is retrieved while iterating over a <p:dataTable>
.
When an image name is empty, the name
attribute of <p:graphicImage>
is evaluated to name=" "
. In which case, it does not work just leaving the page blank without any errors.
If
in the conditional expression is removed then, it causes java.lang.StringIndexOutOfBoundsException
to be thrown.
So, how to display alternate text on <p:graphicImage>
, if the image to display is unavailable?