【发布时间】:2016-05-22 06:01:23
【问题描述】:
使用<p:graphicImage> 显示一个 BLOB 图像,如下所示。
<p:graphicImage value="#{categoryBean.image}">
<f:param name="id" value="7"/>
</p:graphicImage>
CategoryBean 的定义如下。
@Named
@ApplicationScoped
public class CategoryBean {
@Inject
private CategoryService service;
public CategoryBean() {}
public StreamedContent getImage() throws IOException {
FacesContext context = FacesContext.getCurrentInstance();
if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
return new DefaultStreamedContent();
} else {
String id = context.getExternalContext().getRequestParameterMap().get("id");
byte[] bytes = Utils.isNumber(id) ? service.findImageById(Long.parseLong(id)) : null;
return bytes == null ? null : new DefaultStreamedContent(new ByteArrayInputStream(bytes));
}
}
}
关于上述方法,以下自定义标签应该可以正常工作,但它无法在<p:graphicImage> 上显示图像,没有错误/异常。
<my:image bean="#{categoryBean}" property="image" paramName="id" paramValue="7"/>
标签文件位于/WEB-INF/tags/image.xhtml下。
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<p:graphicImage value="#{bean[property]}">
<f:param name="#{paramName}" value="#{paramValue}"/>
</p:graphicImage>
</ui:composition>
生成的<img> 标签看起来不错:
<img id="form:j_idt4"
src="/ContextPath/javax.faces.resource/dynamiccontent.properties.xhtml?ln=primefaces&v=5.3&pfdrid=IA0%2F7ZuBnGS%2BSzeb%2BHyPOTo4Pxp4hjI6&pfdrt=sc&id=7&pfdrid_c=true"
alt=""/>
它只返回一个 HTTP 404 错误。
给定的自定义标签的定义有什么缺陷吗?
【问题讨论】:
-
我并没有感到难过,但是当我发布一个发现长期存在的错误的问题时,是否有一些伪装的 PrimeFaces 不喜欢公开暴露他们的软件中的错误并不断投反对票?
标签: jsf primefaces http-status-code-404 graphicimage tagfile