简体   繁体   中英

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;
    }
}

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.

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}" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM