1

我有下一个代码来加载一组图像,这些图像的流位于名为名称的数据模型中。我的问题是当我在 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>
4

3 回答 3

1

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

于 2010-10-04T03:26:48.743 回答
1

在浪费了几个小时来实现我为这个问题找到的许多解决方案(即包括参数或属性)的过程之后,我设法找到的唯一真正有效的解决方案可以在这里找到:使用 PrettyFaces 提供动态内容

于 2012-02-10T05:50:05.710 回答
0

删除<h:outputText>. 您只能读取一次。不能再读一遍。

至于p:graphicImage零件,您需要为其提供DefaultStreamedContent. 另请参阅此博客条目

于 2010-05-25T15:03:37.340 回答