TCM
TCM

Reputation: 16920

Not getting image in h:graphicImage in JSF

I have this very strange error with h:graphicImage

This code works fine :-

<h:graphicImage value="/Common/Images/#{item.templatePicName}"/>

And this one doesn't :-

<h:graphicImage alt="${app:getCommonImagePath(item.templatePicName)}"  value="${app:getCommonImagePath(item.templatePicName)}" />

It only shows alt value /Common/Images/Sunset.jpg which is perfectly fine and works in 1st case. Then why doesn't it work in 2nd case? There are no problems with my images. They are present in right directory.

here getCommonImagePath is my custom EL function, whose definition is :

package Common;


public final class AppDeployment {

    private AppDeployment(){ //hide constructor

    }

    private static String commonImageFolderPath = "/Common/Images/";
    public static String getCommonImagePath(String picName){
        return commonImageFolderPath + picName;
    }
}

Upvotes: 0

Views: 2693

Answers (2)

Shervin Asgari
Shervin Asgari

Reputation: 24517

Its easier to solve if you have a property in your app class that concatenates what you want.

ie:

class App {
    private String commonImagePath="/Common/Images/";

    //getters and setters
} 

Then you would write:

<h:graphicImage alt="#{app.commonImagePath}#{item.templatePicName}" value="#{app.commonImagePath}#{item.templatePicName}" />

Upvotes: 1

Bozho
Bozho

Reputation: 597402

With JSF you should use #{..} rather than ${..}.

Then check the HTML that is generated to see what the src of the generated image is pointing to.

Then check whether your custom tag is mapped properly.

Upvotes: 2

Related Questions