【发布时间】:2012-02-06 21:36:22
【问题描述】:
我有一个 p:dataGrid 显示公司。这些公司有标志,我想展示他们的标志
在其名称下的 dataGrid 中,但图像未出现在 page 中。只出现了一个破碎的图像方块。
xhtml 代码;
<p:dataGrid value="#{BDS_Company.companyList}" var="cmp" rows="5" columns="3">
<p:column>
<h:panelGrid columns="1">
<h:outputLabel value="#{cmp.cmpName}"/>
<h:outputLabel value="#{cmp.cmpEmail}"/>
<p:graphicImage value="#{BDS_Company.companyLogo(cmp)}"/>
</h:panelGrid>
</p:column>
</p:dataGrid>
托管 bean 代码;
public DefaultStreamedContent companyLogo(BdsCompany company) {
if (company != null) {
if (company.getCmpLogo() != null) {
InputStream is = new ByteArrayInputStream(company.getCmpLogo().getDocFile());
return new DefaultStreamedContent(is);
}
}
return null;
}
当我更改这样的代码时,我会遇到异常“找不到方法 companyLogo”
public DefaultStreamedContent getCompanyLogo(BdsCompany company) {
if (company != null) {
if (company.getCmpLogo() != null) {
InputStream is = new ByteArrayInputStream(company.getCmpLogo().getDocFile());
return new DefaultStreamedContent(is);
}
}
return null;
}
但我使用的另一个页面 getPersonPicture() 显示登录人的个人资料图片并且不带参数效果很好! .我不明白为什么公司的徽标没有出现在页面中:/
任何人都可以帮助我解决这种情况或建议另一种显示图像的方式吗?
提前致谢。
【问题讨论】:
-
问题看起来很像question
-
无论如何而不是返回字节流。有更好的方法可以做到这一点,请参阅question/answer
-
谢谢,但是我需要从 db 获取动态图像,并且我没有问题将参数发送到方法,因为第一个代码需要参数并且可以工作,但只有我认为 p:graphicImage 需要一个 getter
标签: java jsf jsf-2 primefaces