tags:

views:

77

answers:

2

Hello, 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;
    }
}
+2  A: 

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.

Bozho
Hi Bozho,problem was not actually of # or $. I found answer to my own problem. Actually i needed to put double slash and it worked :)private static String commonImageFolderPath = "//Common//Images//";
Ankit Rathod
that is very strange indeed.
Bozho
+1  A: 

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