简体   繁体   English

如果图像不存在,则隐藏graphicImage

[英]Hide graphicImage if image does not exist

I have a graphicImage that takes its value from a servlet (called "picture" - it dynamically serves images stored on the server). 我有一个graphicImage,它从Servlet中获取值(称为“图片”-它动态地提供服务器上存储的图像)。

I would like to hide graphicImage when servlet returns null (no image was found). 当Servlet返回null(未找到图像)时,我想隐藏graphicImage。 I tried using FacesContext.getCurrentInstance().getExternalContext().getResource() but it returns null even for correct URLs. 我尝试使用FacesContext.getCurrentInstance()。getExternalContext()。getResource(),但即使对于正确的URL,它也会返回null。

 <h:graphicImage value="/picture?name=#{myBean.name}" />

if i missunderstand you then sorry. 如果我误解了你,那就对不起。

i would suggest two ways to hide this image: 我建议两种方法来隐藏此图像:

  1. you can check in any ControllerBean (myBean, or ...) if that image exists or not, and passing a rendered Property to JSF UI: 您可以检入任何ControllerBean(myBean或...)是否存在该图像,并将渲染的Property传递给JSF UI:

    <h:graphicImage value="/picture?name=#{myBean.name}" rendered="pictureControler.isFound"/>

  2. or just add alt="" to that image, this image woun't be displayed then. 或仅将alt =“”添加到该图像,那么该图像将不会显示。

    <h:graphicImage value="/picture?name=#{myBean.name}" alt=" "/>

NOTE: the last one not tested but i think should work. 注意:最后一个未经测试,但我认为应该可以。

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

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