我有下一个代码来加载一组图像,这些图像的流位于名为名称的数据模型中。我的问题是当我在 p:datatable 标记内声明 var 时似乎什么都没有。任何想法? 谢谢!
<p:dataTable value="#{controlador.names}" var="nombre" rendered="true">
<p:column rendered="true">
<h:outputText value="#{nombre.stream}"/>
<p:graphicImage value="#{nombre.stream}"/>
</p:column>
</p:dataTable>
最佳答案
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
关于java - 加载一组带有primefaces的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2905813/