[英]Image is unnecessarily displayed on <p:graphicImage> event though the image name from the resources directory is not given
I have stored some images under the webroot\\resources\\fileUpload\\product_image\\thumb
directory so that these images can be displayed on <p:graphicImage>
as follows. 我已经将一些图像存储在webroot\\resources\\fileUpload\\product_image\\thumb
目录下,以便可以按以下方式将这些图像显示在<p:graphicImage>
。
<p:graphicImage library="fileUpload"
name="product_image/thumb/13850470212653732655006325945389_4921.jpg"
alt="Whatever the product name is."/>
If the image name ie 13850470212653732655006325945389_4921.jpg
is not given then, the image should not be displayed but it displays an image from the given URL. 如果未提供图像名称即13850470212653732655006325945389_4921.jpg
,则不应显示该图像,但会显示来自给定URL的图像。
<p:graphicImage library="fileUpload"
name="product_image/thumb/"
alt="Whatever the product name is."/>
The image URL on the web browser appears as follows. Web浏览器上的图像URL如下所示。
/webroot/javax.faces.resource/product_image/thumb/.jsf?ln=fileUpload&v=13850470212653732655006325945389_4921
How does it pick up an image? 它如何拾取图像?
If the resource filename matches \\d+(_\\d+)
, then it's recognized as a versioned resource. 如果资源文件名与\\d+(_\\d+)
匹配,则将其识别为版本化资源。 This is a rarely used feature ( resource library versioning is more common). 这是一个很少使用的功能( 资源库版本控制更为常见)。 Concretely, you can have such a structure: 具体而言,您可以具有以下结构:
WebContent
|-- resources
| `-- js
| `-- script.js
| |-- 1_0.js
| |-- 1_1.js
| `-- 1_2.js
:
(yes, script.js
is here the folder name) (是的, script.js
是这里的文件夹名称)
And when you declare it as follows: 并在声明时如下所示:
<h:outputScript name="js/script.js" />
then automatically the latest one, the 1_2.js
, will be served as per the following generated HTML output, provided a context path of /context
and a JSF mapping of *.xhtml
: 然后自动将最新的1_2.js
用作以下生成的HTML输出,并提供/context
的上下文路径和*.xhtml
的JSF映射:
<script type="text/javascript" src="/context/javax.faces.resource/scripts/script.js.xhtml?v=1_2"></script>
This all is specified in chapter 2.6.1.3 of JSF specification . 所有这些都在JSF规范的 2.6.1.3章中指定。
You've there however a bit unfortunate corner case of using an extensionless folder with a trailing slash as resource name, which should IMO have failed, but it apparently is also accepted by Mojarra. 但是,您可能会遇到一些不幸的情况,即使用无扩展名的文件夹使用带斜杠的后缀作为资源名称,这应该是IMO失败的,但Mojarra显然也接受它。
If you'd like to avoid this behavior, you need to use a different pattern as file name. 如果要避免这种现象,则需要使用其他模式作为文件名。 Eg use -
instead of _
, or use _
as prefix or suffix, or bring in at least one alphabetic character. 例如,使用-
而不是_
或使用_
作为前缀或后缀,或至少引入一个字母字符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.