【问题标题】:Not getting image in h:graphicImage in JSF没有在 JSF 中的 h:graphicImage 中获取图像
【发布时间】:2010-03-31 09:44:30
【问题描述】:

我在 h:graphicImage 中遇到了这个非常奇怪的错误

这段代码运行良好:-

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

而这个没有:-

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

它只显示 alt 值 /Common/Images/Sunset.jpg 非常好,适用于第一种情况。那为什么它在第二种情况下不起作用?我的图像没有问题。它们存在于正确的目录中。

这里的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;
    }
}

【问题讨论】:

    标签: jsf facelets


    【解决方案1】:

    对于 JSF,您应该使用 #{..} 而不是 ${..}

    然后检查生成的 HTML,看看生成的图像的src 指向什么。

    然后检查你的自定义标签是否映射正确。

    【讨论】:

    • 嗨 Bozho,问题实际上不是 # 或 $。我找到了自己问题的答案。实际上我需要放双斜杠并且它起作用了:) private static String commonImageFolderPath = "//Common//Images//";
    【解决方案2】:

    如果您的应用程序类中有一个属性可以连接您想要的内容,则更容易解决。

    即:

    class App {
        private String commonImagePath="/Common/Images/";
    
        //getters and setters
    } 
    

    然后你会写:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-03
      • 2014-09-02
      • 2014-02-26
      • 2011-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多