<p:graphicImage/> failing without any error messages

UI Components for JSF
User avatar
MISS_DUKE
Posts: 273
Joined: 08 Aug 2010, 05:52

13 Oct 2010, 11:33

Markup:

Code: Select all

<p:graphicImage value="#{detailsBacking.photo1}" />
Backing bean code:

Code: Select all

private StreamedContent photo1;
 
public StreamedContent getPhoto1() {
        byte[] myByteArray = meFacade.find(selected).getPhotoOne();//code for MeFacade not shown here
        photo1 = new DefaultStreamedContent(new ByteArrayInputStream(myByteArray) , "image/jpeg");
       if(photo1!=null){
        System.out.print("photo1 is NOT null");
      }
        return photo1;
    }

    public void setPhoto1(StreamedContent photo1) {
        this.photo1 = photo1;
    }
Image is not rendered in the output, and no error message is shown. What am I missing?
JSF implementation: Mojarra V2.1.7
JSF component library: Primefaces V3.1.1
Server: GlassFish Open Source Edition V3.1.1 (build 12)

User avatar
undermensch
Posts: 140
Joined: 08 Jul 2010, 14:37
Location: Florida, United States

13 Oct 2010, 14:27

I posted on this matter yesterday. Displaying image from db does not appear to be working in the Primefaces Showcase either. The generated on-the-fly images display using <p:graphicImage> but the example from a database does not display.
PrimeFaces-11.0.6 / Wildfly 24

User avatar
MISS_DUKE
Posts: 273
Joined: 08 Aug 2010, 05:52

13 Oct 2010, 15:14

Thanks for sharing this issue.

I am now planing to use a Servlet and <h:graphicImage/> tag.
JSF implementation: Mojarra V2.1.7
JSF component library: Primefaces V3.1.1
Server: GlassFish Open Source Edition V3.1.1 (build 12)

User avatar
MISS_DUKE
Posts: 273
Joined: 08 Aug 2010, 05:52

14 Oct 2010, 03:26

I use a Servlet to stream an image from the database and I use the <h:graphicImage/> tag for display as follows:

Code: Select all

<h:graphicImage url="/servletUrl?para1=name1&para2=name2"/>
The problem starts if I include the 2nd parameter (&para2=name2) and I get the following error message:

The reference to entity "para2" must end with the ';' delimiter

Am I missing anything?
JSF implementation: Mojarra V2.1.7
JSF component library: Primefaces V3.1.1
Server: GlassFish Open Source Edition V3.1.1 (build 12)

healeyb
Posts: 365
Joined: 07 Apr 2010, 16:05

15 Oct 2010, 01:00

Without wishing to highjack your post the entire issue of saving and
re-loading an image from a database has been driving me insane.

Everyone seems to think that we store our images in disk files, like it's
the 1970s. I've spent hours attempting to get custom components and
multipart filters to actually do what I want, however, my JSF expertise
is not quite there yet. I do have a reasonably working load image/
restore image from database solution that I'd be very happy to share if
anyone was interested, although it's totallly inefficient but does work.

Regards,
Brendan.

p.s. my solution uses p:fileUpload and h:graphicImage. One of the biggest
problemsto watch out for is if you've tried using the BalusC hh:inputFile
solution and still have the @WebFilter code in your classpath then you'll hit
the 'http error' problem upon loading the file. Took me a while to figure this
out.

User avatar
MISS_DUKE
Posts: 273
Joined: 08 Aug 2010, 05:52

15 Oct 2010, 03:36

I am also just to start to work on the file uploading portion of my project soon.

I have already seen there are many issues posted in this forum complaining about file upload.

I am really happy and very very grateful if you share your experience and codes here.
JSF implementation: Mojarra V2.1.7
JSF component library: Primefaces V3.1.1
Server: GlassFish Open Source Edition V3.1.1 (build 12)

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

15 Oct 2010, 12:26

StreamedContent example for chart seems to be working online;

http://www.primefaces.org/showcase/ui/dynamicImage.jsf

FileUpload component will gone under maintenance soon definitely for 2.3, probably in 2.2

User avatar
MISS_DUKE
Posts: 273
Joined: 08 Aug 2010, 05:52

15 Oct 2010, 14:16

Make File upload available stable for 2.2 please (without the need of Flash at all)
JSF implementation: Mojarra V2.1.7
JSF component library: Primefaces V3.1.1
Server: GlassFish Open Source Edition V3.1.1 (build 12)

User avatar
undermensch
Posts: 140
Joined: 08 Jul 2010, 14:37
Location: Florida, United States

15 Oct 2010, 16:46

But not working for rendering image from database, will that fix make it in 2.2 (I hope)?
PrimeFaces-11.0.6 / Wildfly 24

ethermion
Posts: 117
Joined: 25 Aug 2010, 15:11

15 Oct 2010, 18:17

This is working for me
[code]
public StreamedContent getImage() {
ImageIcon ii = getTestEmployee().getImageIcon();
if (ii == null) return null;
Image i = ii.getImage();
BufferedImage bi = new BufferedImage(i.getWidth(null),i.getHeight(null),BufferedImage.TYPE_INT_RGB);
Graphics g = bi.getGraphics();
g.drawImage(i,0,0,null);
g.dispose();
ByteArrayOutputStream bas = new ByteArrayOutputStream();
try {
ImageIO.write(bi,"png", bas);
} catch (IOException e) {
e.printStackTrace();
}
byte[] data = bas.toByteArray();
InputStream is = new ByteArrayInputStream(data);
return new DefaultStreamedContent(is);
}
[/code]

Starts with an ImageIcon from the database (yuck, I know...)
Does all the transforms in memory - no temp files (good!)
Works (most important!)

Supports the tag
<p:graphicImage value="#{employee.image}"/>

Hope this helps.
Mojarra 2.2.8
Primefaces 5.1
Wildfly 8.2

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 31 guests