1

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?

Tiny
  • 27,221
  • 105
  • 339
  • 599

1 Answers1

1

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.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Changing the file name disallowed the image to display, when a file name is empty. Off topic : the `alt` attribute of `` does not display the alternate text, when an image is unavailable. Is there anything to look into it to display the alternate text? Thank you. – Tiny Nov 22 '13 at 09:33
  • You're welcome. The `alt` is only shown when the `src` is empty. In other words, when `` is `null` or empty. If an invalid resource is specified, it generates a `src="RES_NOT_FOUND"`. I'd add a conditional to omit `product_image/thumb/` if name is null or empty. – BalusC Nov 22 '13 at 09:53