Tiny
Tiny

Reputation: 27899

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.

<p:graphicImage library="fileUpload" 
                name="product_image/thumb/13850470212653732655006325945389_4921.jpg" 
                alt="Whatever the product name is."/>

If the image name i.e 13850470212653732655006325945389_4921.jpg is not given then, the image should not be displayed but it displays an image from the given 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.

/webroot/javax.faces.resource/product_image/thumb/.jsf?ln=fileUpload&v=13850470212653732655006325945389_4921

How does it pick up an image?

Upvotes: 1

Views: 391

Answers (1)

BalusC
BalusC

Reputation: 1108632

If the resource filename matches \d+(_\d+), then it's recognized as a versioned resource. 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)

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:

<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.

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.

If you'd like to avoid this behavior, you need to use a different pattern as file name. E.g. use - instead of _, or use _ as prefix or suffix, or bring in at least one alphabetic character.

Upvotes: 1

Related Questions