p:graphicImage使用另一个请求,因此您需要像这样将标识符传递给managedBean。
<p:dataTable value="#{productManaged.products}" var="productIterated">
<p:column>
<f:facet name="header">
<h:outputText value="#{product.pic}"/>
</f:facet>
<p:graphicImage value="#{productManaged.dynamicProductImage}">
<f:param name="product_id" value="#{productIterated.id}"/>
</p:graphicImage>
</p:column>
</p:dataTable>
你应该注意的另一件事是在StreamedContent中返回一些东西或者会失败。做这样的事情:
public StreamedContent getDynamicProductImage() {
String id = FacesContext.getCurrentInstance()
.getExternalContext().getRequestParameterMap().get("product_id");
if(id!=null && this.products!=null && !this.products.isEmpty()){
Integer productId = Integer.parseInt(id);
for(Product productTemp:this.products){
if(productTemp.getId().equals(productId)){
return new DefaultStreamedContent(
new ByteArrayInputStream(productTemp.getImage()),
productTemp.getMimeType());
}
}
}
return new DefaultStreamedContent(
new ByteArrayInputStream(this.products.get(0).getImage()),
this.products.get(0).getMimeType()); //if you return null here then it won't work!!! You have to return something.
}
,或者你可以阅读这个线程http://primefaces.prime.com.tr/forum/viewtopic.php?f=3&t=4163
它仍然没有工作=( – RhigoHR 2010-05-25 15:49:54
没有必要任何lib ?,我的意思是,defaultStreamedContent到达标记,但问题并没有消失 – RhigoHR 2010-05-25 15:54:23