0

I have tried everything I could in order to render simple image using h:graphicImage in template client. My image is not inside war but on another location on the same disk.

Actually I don't have 'alt' attribute displayed or warning that image cannot be found. My image is found and probably is rendered BUT as empty frame with width and height I specified in h:graphicImage. This empty frame has color of background.

Does anybody know how to render image from outer location as I have not found example of this?

Thank you!

Volodymyr Levytskyi
  • 3,364
  • 9
  • 46
  • 83

1 Answers1

1

The easiest way is to use OmniFaces o:graphicImage. Make a javax.faces.bean.ApplicationScoped bean with method which accepts path of file from filesystem and returns java.io.InputStream. Like that:

JAVA:

@Named
@ApplicationScoped
public class FileReader {

public InputStream getImageByPath(String filename) throws FileNotFoundException{
        return new FileInputStream(new File(filename));
}

}

JSF:

<html xmlns:o="http://omnifaces.org/ui">

<o:graphicImage value="#{fileReader.getImageByPath('/opt/images/admin/112/IMG_1292.JPG')}"/>
stakahop
  • 921
  • 9
  • 18