jsf - 如何渲染 <p :graphicImage> conditionally depending on if the resource exists

标签 jsf graphicimage

如何渲染 <p:graphicImage>仅当资源 URL 有效时?

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

基本上,我只想在 #{resource['images/image.png']} 时呈现我的图形图像实际存在。我怎样才能验证这一点?我试着关注 this JavaScript example ,但我没有成功。

最佳答案

检查是否 ResourceHandler#createResource() 不返回 null .

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

请注意,我替换了 url="#{resource['resourceName']}"通过更简单的 name="resourceName" .

关于jsf - 如何渲染 <p :graphicImage> conditionally depending on if the resource exists,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25570159/

相关文章:

jsf - BLOB 图像仅在通过 p :dataTable is made in PrimeFaces 更新后刷新页面时显示

jsf - 为实体创建主从页面、如何链接它们以及选择哪个 bean 范围

jsf - 何时在 JSF 中命名转换器

java - Seam 使用凭证自动登录

java - 在基于 JSF 的 Web 应用程序中显示图像

primefaces - 带有 StreamedContent 的动态图像

jsf - 如何使用<p :graphicImage> with DefaultStreamedContent in an ui:repeat?

jsf - p :steps but enable click on all steps

jsf - <p :graphicImage> throws javax. el.PropertyNotFoundException on #{bean.foo().bar()},但 #{bean.fooAndBar()} 有效

jsf - PrimeFaces 6.0 不在客户端缓存图片