Posted under JSF
Permalink
Tags CSS, Facelets, Glassfish, Gotcha, JSF, Logging, Primefaces, Tip
I needed to load a custom style sheet for a composite component.
Primefaces has problems loading theme images correctly when using h:outputStylesheet as per here, but using a raw link tag was no good as I wanted to develop a custom component which loaded its own styles, i.e. it had no <head> section.
This post here indicates that if you don’t use the library attribute you can get h:outputStylesheet to work even with Primefaces themes.
In my case, I was not loading themes/images etc. so this was not an issue, but I still used the following directive and avoided use of the library attribute for simplicity:-
<h:outputStylesheet name=”uk.co.salientsoft/util/SSBreadcrumb.css”/>
This version worked. My initial attempts (which failed with a resource loading error) were as follows :-
<h:outputStylesheet name=”resources/uk.co.salientsoft/util/SSBreadcrumb.css”/>
<h:outputStylesheet name=”#{request.contextPath}/resources/uk.co.salientsoft/util/SSBreadcrumb.css”/>
In other words, with a css file stored in Eclipse under WebContent/resources/uk.co.salientsoft/util/SSBreadcrumb.css, the above working example was correct, i.e. to load correctly, omit the context root and the resources level and use a relative reference without the preceding slash.
I did try to debug this by visiting the logger settings in Glassfish admin, then under the Log Levels tab, setting everything with JSF in it to finest! This did display an error when trying to load the resource:-
[#|2011-02-11T17:21:13.331+0000|FINE|glassfish3.0.1|javax.enterprise.resource.webcontainer.jsf.application|_ThreadID=31;_ThreadName=Thread-1;
ClassName=com.sun.faces.application.resource.ResourceHandlerImpl;MethodName=logMissingResource;
|JSF1064: Unable to find or serve resource, /SSBreadcrumb/resources/uk.co.salientsoft/util/SSBreadcrumb.css.|#]
However the error was not particularly informative as it just spat back to me the path I gave it to load. It would have been nice for it to tell me how it was mapping the path as then I could have seen the problem more easily.
Note however that using this page in Glassfish is a very convenient way to turn on logging in Glassfish, as it lists the common logger paths for you and gives a combo to select the level for each. You don’t have to go googling for the logger paths and edit a log properties file yourself. Note also that when you do this you must restart Glassfish for the log level changes to actually take effect.
Leave a Reply
You must be logged in to post a comment.