jsfgraphicimage

h:graphicImage does not display image in JSF


I have this in my class and I am trying to access it on my web page.

public String carImageURL = "/resources/images/sample_car.jpg";

This is the code I use in my web page that does not work.

<h:graphicImage value="#{carClass.carImageURL}"></h:graphicImage >

When I run the page there is no picture of the car in it.


Solution

  • Change the carImageURL attribute to private scope and write a getter method for it. Also write a slash at the beginning of the image path:

    private String carImageURL = "/resources/images/sample_car.jpg";
    
    public String getCarImageURL() {
        return carImageURL;
    }