p:dataGrid 内的 p:graphicImage 仅显示空白图像
我正在尝试使用字节数组(作为保存在数据库中的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在此特定上下文中的
binding
属性并没有给我一种良好的感觉,即您正在以正确的方式使用它。将其删除。value
属性似乎也没有指向UIData
的迭代变量#{item}
。相应地修复它。
然后,
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. Thevalue
attribute also doesn't seem to point to theUIData
's iterated variable#{item}
.Fix it accordingly.
The
Item
class should then have aprivate 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.