This is a utility class to render link to resources used by custom components.
Mostly used to avoid having to include
in the head of the pages before using a component.
addInlineStyleToHeader
public static void addInlineStyleToHeader(String inlineStyle,
FacesContext context)
Adds the given Style Sheet to the document Header.
If the style sheet is already has already been referenced, it's added only once.
addJavaScriptHere
public static void addJavaScriptHere(Class componentClass,
String resourceFileName,
FacesContext context)
throws IOException
Adds the given Javascript resource to the document body, without passing UIComponent.
addJavaScriptHere
public static void addJavaScriptHere(Class componentClass,
String resourceFileName,
FacesContext context,
UIComponent component)
throws IOException
Adds the given Javascript resource to the document body.
addJavaScriptToHeader
public static void addJavaScriptToHeader(Class componentClass,
String resourceFileName,
FacesContext context)
Adds the given Javascript resource to the document Header.
If the script is already has already been referenced, it's added only once.
addJavaScriptToHeader
public static void addJavaScriptToHeader(Class componentClass,
String resourceFileName,
boolean defer,
FacesContext context)
Adds the given Javascript resource to the document Header.
If the script is already has already been referenced, it's added only once.
addStyleSheet
public static void addStyleSheet(Class componentClass,
String resourceFileName,
FacesContext context)
Adds the given Style Sheet to the document Header.
If the style sheet is already has already been referenced, it's added only once.
getComponentName
protected static String getComponentName(Class componentClass)
getResourceMappedPath
public static String getResourceMappedPath(Class componentClass,
String resourceFileName,
FacesContext context)
Get the Path used to retrieve an internal resource for a custom component.
Example : You can use this to initialize javascript scripts so that they know the path of some other resources
(image, css, ...).
AddResource.addJavaScriptOncePerPage(HtmlCalendarRenderer.class, "popcalendar.js", facesContext,
"jscalendarSetImageDirectory("+AddResource.getResourceMappedPath(HtmlCalendarRenderer.class, "DB", facesContext)+")");
Note : set context to null if you want the path after the application context path.
getResourceMappedPath
protected static String getResourceMappedPath(String componentName,
String resourceFileName,
String contextPath)
hasAdditionalHeaderInfoToRender
public static boolean hasAdditionalHeaderInfoToRender(HttpServletRequest request)
isResourceMappedPath
public static boolean isResourceMappedPath(HttpServletRequest request)
serveResource
public static void serveResource(HttpServletRequest request,
HttpServletResponse response)
throws IOException
writeWithFullHeader
public static void writeWithFullHeader(HttpServletRequest request,
ExtensionsResponseWrapper responseWrapper,
HttpServletResponse response)
throws IOException
Add the resources to the <head> of the page.
If the head tag is missing, but the <body> tag is present, the head tag is added.
If both are missing, no resources is added.
TODO : Change the ordering so that the user header CSS & JS override MyFaces' ones.