简体   繁体   English

在JSF中未在h:graphicImage中获取图像

[英]Not getting image in h:graphicImage in JSF

I have this very strange error with h:graphicImage 我的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. 它仅显示alt值/Common/Images/Sunset.jpg,该值非常好,并且在第一种情况下可以使用。 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 : 这里的getCommonImagePath是我自定义的EL函数,其定义是:

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 ${..} . 使用JSF,您应该使用#{..}而不是${..}

Then check the HTML that is generated to see what the src of the generated image is pointing to. 然后检查所生成的HTML,以查看所生成图像的src指向什么。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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