Reputation: 181
In a JSF page, I use EL to locate an image which placed in /resource/images/
folder.
<h:graphicImage value="#{resource['images:logo.gif']}"
How can EL locate the image? Maybe a specification defines the rule, but I don't know which specification. I try to find it in the JSR-000344 JavaServer Faces 2.2 ,the JSR-000342 Java Platform, Enterprise Edition 7, the JSR-000341 Expression Language 3.0, but not found.
Upvotes: 2
Views: 1767
Reputation: 1109665
In the JSF 2.0 specification, it's first mentioned in chapter 2.6.2:
2.6.2 Rendering Resources
Resources such as images, stylesheets and scripts use the resource handling mechanism as outlined in Section 2.6.1 “Packaging Resources”. So, for example:
<h:graphicImage name=”Planets.gif” library=”images”/> <h:graphicImage value=”#{resource[‘images:Planets.gif’]}”/>
These entries render exactly the same markup. In addition to using the
name
andlibrary
attributes, stylesheet and script resources can be “relocated” to other parts of the view. For example, we could specify that a script resource be rendered within an HTML “head”, “body” or “form” element in the page.
and then in chapter 5.6.2.5:
5.6.2.5 Resource ELResolver
This resolver is a means by which
Resource
instances are encoded into a faces request such that a subsequent faces resource request from the browser can be satisfied using the ResourceHandler as described in Section 2.6 “Resource Handling”.ELResolver method implementation requirements
If base and property are not null, and base is an instance of
ResourceHandler
(as will be the case with an expression such as#{resource[‘ajax.js’]}
, perform the following. (Note: This is possible due to theImplicitObjectELResolver
returning theResourceHandler
, see Section 5.6.2.1 “Implicit Object ELResolver for Facelets and Programmatic Access”)
- If property does not contain a colon character ‘:’, treat property as the
resourceName
and pass property toResourceHandler.createResource(resourceName)
.- If property contains a single colon character ‘:’, treat the content before the ‘:’ as the
libraryName
and the content after the ‘:’ as theresourceName
and pass both toResourceHandler.createResource(resourceName, libraryName)
- If property contains more than one colon character ‘:’, throw a localized
ELException
, including property.If one of the above steps results in the creation of a non-null
Resource
instance, callELContext.setPropertyResolved(true)
and return the result of calling thegetRequestPath()
method on theResource
instance.
It's also mentioned in same chapters in JSF 2.1 and 2.2 specification.
Unrelated to the concrete problem, images
is a really bad example of a resource library name. Don't take over that from the spec example.
Upvotes: 6