p:dataGrid 内的 p:graphicImage 仅显示空白图像

发布于 2024-11-28 21:12:04 字数 2004 浏览 0 评论 0原文

我正在尝试使用字节数组(作为保存在数据库中的 BLOB)将 StreamedContent 返回到 ap:datagrid 内的 p:graphicImage,如下所示:

<p:dataGrid id="dtResults" rows="10" columns="3"
    value="#{searchResultsController.items}" var="item">
    <p:column>
        <p:panel header="#{item.displayName}" style="text-align:center">
            <h:panelGrid columns="1" style="width:100%">
                <p:graphicImage binding="#{imagestickiesController.imageforuserid}"
                    width="100" height="100" value="#{imagestickiesController.image}">
                    <f:attribute  name="uID" value="#{item.userID}" />
                </p:graphicImage>
                <h:outputText id="lAboutMe" value="#{item.aboutMe}"/>
            </h:panelGrid>
        </p:panel>
    </p:column>
</p:dataGrid>

这个返回空白图像。有人知道为什么吗?

额外: 在此上下文中,ImagestickiesController 的部分是:

  public class ImagestickiesController {

private GraphicImage imageforuserid;

public GraphicImage getImageforuserid(){
    return imageforuserid;
}

public void setImageforuserid(GraphicImage gi){
    imageforuserid = gi;
}

    public StreamedContent getImage(){
        System.out.println("In getImage");
        System.out.println(imageforuserid);
        System.out.println(imageforuserid.getAttributes().get("uID"));
        Long value = (Long)imageforuserid.getAttributes().get("uID");
        if (value!=null)
        {
           Imagestickies curr =  ejbFacade.FindByUserID(value);
           if (curr!=null)
           {
               System.out.println(curr);
                InputStream is = new ByteArrayInputStream(curr.getStickies().getContent());
                StreamedContent res = new DefaultStreamedContent(is);
                return res;
            }
        }
       return null;
    }
}

ejbFacade 向数据库进行查询。我已经打印了以字节为单位的图像结果的大小,并看到它没问题,但图像仍然没有显示...... 另一件事是,由于设计的限制,项目(用户实体)无法到达数据库内的图像。

谢谢...

I'm trying to use byte array (as BLOB saved in DB) to return the StreamedContent to the p:graphicImage, that is inside a p:datagrid, as follows:

<p:dataGrid id="dtResults" rows="10" columns="3"
    value="#{searchResultsController.items}" var="item">
    <p:column>
        <p:panel header="#{item.displayName}" style="text-align:center">
            <h:panelGrid columns="1" style="width:100%">
                <p:graphicImage binding="#{imagestickiesController.imageforuserid}"
                    width="100" height="100" value="#{imagestickiesController.image}">
                    <f:attribute  name="uID" value="#{item.userID}" />
                </p:graphicImage>
                <h:outputText id="lAboutMe" value="#{item.aboutMe}"/>
            </h:panelGrid>
        </p:panel>
    </p:column>
</p:dataGrid>

This one returns blank images. Is someone have an idea why?

ADDED:
The part of the ImagestickiesController in this context is:

  public class ImagestickiesController {

private GraphicImage imageforuserid;

public GraphicImage getImageforuserid(){
    return imageforuserid;
}

public void setImageforuserid(GraphicImage gi){
    imageforuserid = gi;
}

    public StreamedContent getImage(){
        System.out.println("In getImage");
        System.out.println(imageforuserid);
        System.out.println(imageforuserid.getAttributes().get("uID"));
        Long value = (Long)imageforuserid.getAttributes().get("uID");
        if (value!=null)
        {
           Imagestickies curr =  ejbFacade.FindByUserID(value);
           if (curr!=null)
           {
               System.out.println(curr);
                InputStream is = new ByteArrayInputStream(curr.getStickies().getContent());
                StreamedContent res = new DefaultStreamedContent(is);
                return res;
            }
        }
       return null;
    }
}

The ejbFacade makes the query to the DB. I've printed the size of the resulted imaged in bytes, and saw it was OK, but still the image is not shown...
Another thing is that the item (User entity) cannot reach the image within the DB due to restrictions in the design.

Thanks...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墟烟 2024-12-05 21:12:04

在此特定上下文中的 binding 属性并没有给我一种良好的感觉,即您正在以正确的方式使用它。将其删除。 value 属性似乎也没有指向 UIData 的迭代变量 #{item}

相应地修复它。

<p:graphicImage width="100" height="100" value="#{item.image}">

然后,Item 类应该有一个带有 getter 的 private StreamedContent image 属性。

如果这不是 Item 类中某些设计限制的选项,那么您确实必须显示您的 #{imagestickiesController} 代码,因为它绝对是罪魁祸首。

The binding attribute in this particular context doesn't give me a good feeling that you're using it the right way. Remove it. The value attribute also doesn't seem to point to the UIData's iterated variable #{item}.

Fix it accordingly.

<p:graphicImage width="100" height="100" value="#{item.image}">

The Item class should then have a private StreamedContent image property, with a getter.

If that's not an option for some design restrictions in the Item class, then you really have to show your #{imagestickiesController} code as it's definitely the whole culprit.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文