How to render

conditionally depending on if th

2019-02-23 08:10发布

How can I render a <p:graphicImage> only if the resource URL is valid?

<p:graphicImage url="#{resource['images/image.png']}" />

Basically, I would like to render my graphicImage only if #{resource['images/image.png']} actually exists. How can I validate this? I tried to follow this JavaScript example, but I didn't succeed.

2条回答
smile是对你的礼貌
2楼-- · 2019-02-23 08:37

Check if ResourceHandler#createResource() doesn't return null.

<p:graphicImage name="images/image.png" rendered="#{not empty facesContext.application.resourceHandler.createResource('images/image.png')}"/>

Note that I replaced url="#{resource['resourceName']}" by a much simpler name="resourceName".

查看更多
混吃等死
3楼-- · 2019-02-23 08:47

I don't use url, rather combination of name and library...

This works for me .... Hope it helps

<h:dataTable id="image" value="#bb.getCurrentBorrowerImage(history.borrower_id)}" var="i" >
<h:column rowHeader="">
<h:graphicImage name="#{i.imageFileName}" library="borrower_images" alt="Item Image"   height="100" width="100" rendered="#{!empty i.imageFileName}"/>
</h:column>

查看更多
登录 后发表回答