简体   繁体   English

如何渲染 <p:graphicImage> 有条件地取决于资源是否存在

[英]How to render <p:graphicImage> conditionally depending on if the resource exists

How can I render a <p:graphicImage> only if the resource URL is valid? 仅当资源URL有效时,如何才能呈现<p:graphicImage>

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

Basically, I would like to render my graphicImage only if #{resource['images/image.png']} actually exists. 基本上,我只想在#{resource['images/image.png']}实际存在的情况下渲染我的graphicImage。 How can I validate this? 我该如何验证? I tried to follow this JavaScript example , but I didn't succeed. 我试着按照这个JavaScript示例 ,但我没有成功。

Check if ResourceHandler#createResource() doesn't return null . 检查ResourceHandler#createResource()是否不返回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" . 请注意,我用更简单的name="resourceName"替换了url="#{resource['resourceName']}" name="resourceName"

I don't use url, rather combination of name and library... 我不使用url,而是使用名称和库的组合......

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM