p:dataGrid中的p:graphicImage仅显示空白图像
我正在尝试使用字节数组(作为保存在DB中的BLOB)将StreamedContent返回到p:dataGrid中的p:graphicImage,如下所示:
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?
已添加: 在这种情况下,ImagestickiesController的部分是:
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;
}
}
ejbFacade向数据库进行查询.我已经打印出了以字节为单位的结果图像的大小,发现还可以,但是仍然没有显示图像........................................................................ 另一件事是,由于设计上的限制,项目(用户实体)无法到达数据库中的图像.
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.
谢谢...
在此特定上下文中的binding
属性不会给我很好的感觉,即您使用的方式正确.去掉它. value
属性似乎也没有指向UIData
的迭代变量#{item}
.
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}
.
相应地修复它.
<p:graphicImage width="100" height="100" value="#{item.image}">
Item
类应具有一个带有吸气剂的private StreamedContent image
属性.
The Item
class should then have a private StreamedContent image
property, with a getter.
如果不是Item
类中某些设计限制的选项,那么您真的必须显示#{imagestickiesController}
代码,因为它绝对是罪魁祸首.
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.