Resolve Resource URLs in UIComponents
- Dominant language
- Java
- Stars
- 127
- Forks
- 59
- Avg merge
- 23h
- Merged PRs (30d)
- 7
Description
The purpose of this enhancement request is to make it easier to reference
resource URLs in custom components.
In JSF 2, a great EL shortcut was introduced to get the url for resources using
the resource implicit object (e.g. #resource['/library/image.jpg']). But there
is no easy programmatic way of resolving resource URLs inside a custom
component. For example if an image resource lies inside
META-INF/resources/library/image.jpg, there is no convenient way of referencing
the path of the image when writing an "img" tag inside my UIComponent.
Ideally such method should exist in ResourceHandler and users can invoke it
using
facesContext.getApplication().getResourceHandler().getRequestPath("image.jpg","library"),
but resource handler has no such method to find a resource in META-INF/resources.
In lieu of this, you can do the following (Suggested by Ed Burns):
ResourceHandler rh = facesContext.getApplication.getResourceHandler();
Resource r = rh.createResource("image.jpg", "library");
rh.getRequestPath();
This would work, but it is not as nice as getResourceHandler().getRequestPath().
This will give Component developers some ease, especially when there are
implementing components that deal with javascript extensively.
Thanks.
#### Environment
Operating System: All
Platform: All
URL: [http://forums.java.net/jive/thread.jspa?messageID=395511](http://forums.java.net/jive/thread.jspa?messageID=395511)
#### Affected Versions
[2.0]
Contributor guide
Research direction
Start with the ResourceHandler API and the existing createResource("image.jpg", "library") and getRequestPath() flow described in the issue. Determine how a ResourceHandler-level request-path method should resolve resources under META-INF/resources for custom UIComponents, then verify that the resulting URL works for component-generated image or JavaScript tags.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, frontend, web-dev
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100