The Trinidad source code does the "/" encoding on its
own, without calling the ViewHandler - see the toURL()
method in CoreRenderer.  We actually do a bit more than
others - "//" gets turned to "/", which is very helpful
since the default strategy gives you no way to output
a server-relative URL (only page-relative, context-relative,
and absolute)!

So, Trinidad should call ExternalContext.encodeResourceURL()
and only that method.

Frankly, I haven't the faintest idea why we (the JSF EG) added
ViewHandler.getResourceURL()!  Perhaps I've forgotten the
salient points, but ExternalContext has always seemed
sufficient.

-- Adam



On 9/3/06, Martin Koci <[EMAIL PROTECTED]> wrote:

Hello,

I don't understand how to encode src attributes on HTML elements.  There
are two methods:
ExternalContext.encodeResourceURL and ViewHandler.getResourceURL.

MyFaces button renderer uses both:
String src =
context.getApplication().getViewHandler().getResourceURL(context,
imageSrc);
writer.writeURIAttribute("src",
context.getExternalContext().encodeResourceURL(src), "image");

This solutions works (in my app) and handles both situation - relative
paths and absolute paths starting with "/".

Taken from RI javadoc: NavigationHandler.getResourceURL:
Return a URL suitable for rendering (after optional encoding perfomed by
the encodeResourceURL() method of ExternalContext) that selects the
specifed web application resource. If the specified path starts with a
slash, it must be treated as context relative; otherwise, it must be
treated as relative to the action URL of the current view.

This method handles context relative paths with "/", Sun RI 1.2 uses
this method too, code from ButtonRenderer:

private String src(FacesContext context, String value) {
        if (value == null) {
            return "";
        }
        value = context.getApplication().getViewHandler().
            getResourceURL(context, value);
        return (context.getExternalContext().encodeResourceURL(value));
    }

I seems than calling ExternalContext.encodeResourceURL in renderers is
not enough.

Regards,

Martin


Reply via email to