如下使用<p:graphicImage>
顯示BLOB圖像。在標記文件中使用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球員誰不喜歡公開他們的軟件不斷暴露錯誤下投票,當我張貼問題揭示了長期存在的BUG? – Tiny