我有一个 p:dataGrid,它显示公司。这些公司有 Logo ,我想展示他们的 Logo
在 dataGrid 的名称下,但图像不会出现在 page 中。只出现一个 splinter 的图像方 block 。
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() 的另一个页面,它显示了登录人员的个人资料图片并且不带参数,效果很好! 。我不明白为什么公司的 Logo 没有出现在页面中:/
任何人都可以帮助我解决这种情况或建议另一种显示图像的方式吗?
提前致谢。
最佳答案
为graphicImage值创建一个字符串url(/images/company.png)来代替DefaultStreamedContent。编写一个 servlet,添加到 web.xml 并映射您的图像 url (/images/*)。
在 servlet doGet 中对数据库执行任何操作,并返回图像流作为响应。
http://rajivas.wordpress.com/tag/writing-directly-to-response-stream-in-jsf/
关于java - 如何在 p :dataGrid using p:graphicImage 中显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9167606/