简体   繁体   English

<p:graphicImage>在jsf中不起作用

[英]<p:graphicImage> not working in jsf

I recently included a <p:galleria> in my JSF page as shown in PrimeFaces showcase. 我最近在我的JSF页面中包含了一个<p:galleria> ,如PrimeFaces展示中所示。 The code is executing without any errors, but it doesn't displaying any images. 代码正在执行而没有任何错误,但它不显示任何图像。 I think this is due to the incorrect path format for the images. 我认为这是由于图像的路径格式不正确。 How is this caused and how can I solve it? 这是怎么造成的,我该如何解决?

index.xhtml

<p:galleria value="#{compa.images}" var="image" panelWidth="1570" panelHeight="250" showCaption="true">  
    <p:graphicImage value="resource/images/#{image}"  name="COMPANY CREATION"/>  
</p:galleria> 

compa.java

public void init() {  
    images = new ArrayList<String>();  

    for(int i=1;i<=10;i++) {  
        images.add("resource/images" + i + ".jpg");  
    }  
}

The images path in IDE is ps\\build\\web\\resource\\images . IDE中的图像路径是ps\\build\\web\\resource\\images

First of all, JSF is in the context of this question merely a HTML code generator. 首先,JSF在这个问题的上下文中只是一个HTML代码生成器。 In HTML, images are represented by the <img> element whose src attribute should point to a (relative) URL from which the webbrowser could download the image individually. 在HTML中,图像由<img>元素表示,其中src属性应指向(相对)URL,webbrowser可以从中单独下载图像。 Have you checked the generated HTML output by opening the JSF page in webbrowser and doing rightclick and View Source ? 您是否通过在webbrowser中打开JSF页面并右键单击和查看源来检查生成的HTML输出? Do the generated <img> elements look all right? 生成的<img>元素看起来好吗? Likely not. 可能不是。

The way how you used the name attribute is incorrect. 您使用name属性的方式不正确。

<p:graphicImage value="resource/images/#{image}"  name="COMPANY CREATION"/>  

The name attribute represents the "resource name". name属性表示“资源名称”。 It's basically the path to the resource, relative from the /resources folder on. 它基本上是资源的路径,相对于/resources文件夹。 This attribute has precedence over value attribute. 此属性优先于value属性。 So basically you're trying to create 所以基本上你要创造

<img src="COMPANY CREATION" />

This is not right. 这个不对。 JSF would instead auto-generate a RES_NOT_FOUND URL. 相反,JSF会自动生成RES_NOT_FOUND URL。 You should have seen that in the generated HTML output. 您应该在生成的HTML输出中看到它。

Provided that your intent is to show "COMPANY CREATION" as tooltip, then the right way is 如果您的意图是将“公司创建”显示为工具提示,那么正确的方法是

<p:graphicImage name="images/#{image}" title="COMPANY CREATION" />

Or, if you insist in using value attribute, which takes a context-relative URL instead of a resource name: 或者,如果您坚持使用value属性,该属性采用上下文相关URL而不是资源名称:

<p:graphicImage value="/resources/images/#{image}" title="COMPANY CREATION" />

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

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