0

I have a problem with dynamically loaded CSS files in a JSF application running on tomcat 7.

If I load the CSS file on a static way like

<link href="mystyle.css" rel="stylesheet" type="text/css">

all is ok and the web page looks fine. But if I trying to load the CSS file dynamically like

<link href="#{pageManagerBean.getCSSFile()}" rel="stylesheet" type="text/css">

where pageManagerBean.getCSSFile() returns "mystyle.css", the CSS file will be not loaded. The browser gets from tomcat a "404 - Not found". But if I doing a browser refresh the CSS file is found and the web site looks fine.

Steffen
  • 2,500
  • 4
  • 31
  • 47
  • So the page loads normally, except the css is not present? or does the whole page 404? if the first what does the the rendered html look like? – BevynQ Jul 24 '13 at 05:31
  • No. The page is loading fine. Only the style rules of the CSS file are missing. I see in Chrome the browser get a "404" from the tomcat while loading the expected CSS file. – Steffen Jul 24 '13 at 06:48
  • Remove the `get` and the parentheses, just call the property: `#{pageManagerBean.CSSFile}` – Aritz Jul 24 '13 at 07:00
  • @Biker: It's the same. Also if I look at the generated HTML code, I see that the JSF framefork replace the code with the correct CSS file name. The is then 100% identical to the static . But only tomcat returns a "404" for that file – Steffen Jul 24 '13 at 07:09
  • Look at [this](http://stackoverflow.com/a/9275034/1199132) the last code piece achieves exactly what you want. You can also try with `` tag, which is JSF's default way to include style files. However if Tomcat returns 404 for the file itself, you haven't got it in your deploy directory. – Aritz Jul 24 '13 at 07:22
  • Are you on the fly generating CSS files in deploy folder or so..? Why? – BalusC Jul 24 '13 at 14:20
  • @BalusC: Yes, that's correct. We are displaying multimedia content and the content can be changed at runtime. But I have rewritten some parts of the application so that we don't need longer tu update (hot deploy) the CSS content. Only the xhtml files will be hot deploys and that works fine. Thanks to all. – Steffen Jul 25 '13 at 08:27
  • Then your concrete problem basically duplicates this: http://stackoverflow.com/questions/8885201/uploaded-image-only-available-after-refreshing-the-page/ Key is: don't write to deploy folder! – BalusC Jul 25 '13 at 11:22

0 Answers0