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