webtier@glassfish.java.net

Re: [webtier] JSF 2 How to resolve Resource URLs in UIComponents

From: Ed Burns <edward.burns_at_oracle.com>
Date: Mon, 29 Mar 2010 07:52:24 -0700

>>>>> On Sun, 28 Mar 2010 02:42:16 -0700 (PDT), webtier_at_javadesktop.org said:

R> In JSF 2, a great EL shortcut was introduced to get the url for
R> resources using #resource['/library/image.jpg'].

R> I would like to get the URL of an image inside a custom component
R> using an equivalent java syntax. The image resource lies inside

Your request indicates the need for a much simpler way to do this. It
*can* currently be done (see below), but I want you to please add an
issue to the https://javaserverfaces-spec-eg.dev.java.net/ issue tracker
requesting this feature (I've given you permission to add it).

R> I have been looking around
R> [i]facesContext.getApplication().getResourceHandler()[/i], but
R> resource handler has no such method to find a resource in
R> META-INF/resources.

What I'm about to say will feed the trolls who say JSF is too complex,
so let me start by saying we'll add something like this to satisfy your
request (this doesn't exist yet, but is trivial to implement)

facesContext.getApplication.getResourceHandler().getRequestPath("image.jpg",
"library");

In lieu of this, you must do the following:

ResourceHandler rh = facesContext.getApplication.getResourceHandler();

Resource r = rh.createResource("image.jpg", "library");
rh.getRequestPath();

I know, it's horribly complex and would by much simpler in Wicket, but,
hey, at least you can do it. Oh, wait, Wicket doesn't have a resources
feature. Hmm.

Ed

-- 
| edward.burns_at_oracle.com  | office: 408 884 9519 OR x31640
| homepage:                | http://ridingthecrest.com/