3
votes

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...

1

1 Answers

3
votes

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.