如果没有图像,我有两个<o:graphicImage>来显示存储的图像和一个虚拟图像。实际上,存储的图像的大小可以是零。如果是这样,则呈现第一个<o:graphicImage,但图像为空且未正确呈现。
<o:graphicImage id="image" alt="Image"
lastModified="#{userProfile.user.lastModified}"
rendered="#{not empty images.getImage(userProfile.user.id)}"
value="#{images.getImage(userProfile.user.id)}"
<o:graphicImage name="images/profile.png" width="125"
rendered="#{empty images.getImage(userProfile.user.id)}" />如果用户图像为空或长度/大小为0,如何显示虚拟图像?
发布于 2015-05-26 18:39:18
最好不要在rendered属性中调用该图像流方法。它在JSF生命周期中被多次调用,因此每次都无法有效地从DB获取图像字节。
这个模型一开始看起来也不太对。我建议你换个型号。将图像ID设为User或UserProfile表和实体的FK。
@Column(name="image_id")
private Long imageId;然后,当用户上传/设置图像时,将图像ID保存在那里。这样您就可以使用它,如下所示:
<o:graphicImage
value="#{images.getImage(userProfile.user.imageId)}"
rendered="#{not empty userProfile.user.imageId}" />
<h:graphicImage
name="images/profile.png"
rendered="#{empty userProfile.user.imageId}" />不要忘记修改映像流,通过自己的ID而不是用户ID来获取图像。
https://stackoverflow.com/questions/30466243
复制相似问题