tag:blogger.com,1999:blog-36773632.post6451936460945855149..comments2023-12-19T08:40:05.062-05:00Comments on Java Evangelist John Yeary: JSF Trick of the Day: CSS and ELJohn Yearyhttp://www.blogger.com/profile/00461192445071361043noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-36773632.post-58231770488093570732011-08-25T22:03:08.656-05:002011-08-25T22:03:08.656-05:00Eric that is not true. You can use the same trick ...Eric that is not true. You can use the same trick on an external css file. However, you must use a JSF tag to load it.<br /><br /><h:outputStylesheet library="css" name="style.css"/><br /><br />style.css has the following:<br /><br /> body {<br /> background-image: url('#{facesContext.externalContext.requestContextPath}/resources/images/background.gif');<br /> }<br /><br /> It loads completely fine as I would expect with the correct background image.John Yearyhttps://www.blogger.com/profile/00461192445071361043noreply@blogger.comtag:blogger.com,1999:blog-36773632.post-27089881732045650082011-08-25T21:16:49.197-05:002011-08-25T21:16:49.197-05:00if the following css is in an external CSS file, l...if the following css is in an external CSS file, let's say /resources/css/myapp.css, it cannot do that. JSF framework should solve this. Furthermore, sometimes we also need to know the context path from Javascript. This also not work in external javascript files. I think JSF framework should provide us some method to retrieve the context path from the resources. In the JSP, we can just rename the .css or .js into .jsp. The application server will treat them as a JSP page. <br /><br />background-image: url('#{facesContext.externalContext.requestContextPath}/resources/images/background.gif');Eric Chowhttps://www.blogger.com/profile/16995997072042857836noreply@blogger.comtag:blogger.com,1999:blog-36773632.post-9067892973051061042011-08-09T08:56:58.352-05:002011-08-09T08:56:58.352-05:00Thanks for posting the shorter version. This is a ...Thanks for posting the shorter version. This is a better solution for the more general case.<br /><br />I was trying to point out that you have access to the whole FacesContext which I did not really make clear in my post.John Yearyhttps://www.blogger.com/profile/00461192445071361043noreply@blogger.comtag:blogger.com,1999:blog-36773632.post-6078623655562769602011-08-09T08:36:00.531-05:002011-08-09T08:36:00.531-05:00Great post. This question still gets asked a lot. ...Great post. This question still gets asked a lot. You can, however, make it shorter by used #{request.contextPath}.Anonymousnoreply@blogger.com