4

I am creating multi-language web based application using JSF 2.0.

For css earlier I was using

<h:outputStylesheet library="css" name="setFontForAll.css"/>

and inside CSS file I had

font-size: #{msg['myDir'].contains('LTR')?'10pt':'14pt'};
                                           ^^^     ^^^
                                          English Arabic

However due to CSS caching, same CSS file is there and I am getting font as 10pt continously even if I choose Arabic.

Hence I added time after CSS.

<h:outputStylesheet library="css" name="setFontForAll.css?#{language.myTimeinMill}"/>

However when I use this, all my CSS goes for toss... I see default page setup (no css is getting invoked)

When I see view source, I get <link type="text/css" rel="stylesheet" href="RES_NOT_FOUND" />

Any idea what I am doing wrong?

Note : I am using JSF 2.0


I am also printing #{language.myTimeinMill} inside body and everytime I see different time.

Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276

2 Answers2

2

The only way I see is using the plain <link> tag.

There is no possibility by using <h:outputStylesheet /> to add a parameter in the URL. One answer on this subject doesn't work anymore on JSF 2.0 :

<h:outputStylesheet target="head" name="blank.css">
    @import url('css/setFontForAll.css?version=#{language.myTimeinMill}')
</h:outputStylesheet>

It returns a message :

com.sun.faces.renderkit.html_basic.ScriptStyleBaseRenderer encodeChildren INFO: outputScript with "name" attribute and nested content. Ignoring nested content.

That said, I suggest this solution :

<link type="text/css" rel="stylesheet" href="#{request.contextPath}/resources/css/setFontForAll.css?ln=css&amp;version=#{language.myTimeinMill}" />

<ui:fragment rendered="#{msg['myDir'].contains('LTR')}">
    <link type="text/css" rel="stylesheet" href="#{request.contextPath}/resources/css/setFontOverride.css?ln=css&amp;version=#{language.myTimeinMill}" />
</ui:fragment>
Community
  • 1
  • 1
Alexandre Lavoie
  • 8,711
  • 3
  • 31
  • 72
  • This is working, but now I am facing another problem. In CSS file I have `font-size: #{msg['myDir'].contains('LTR')?'10pt':'14pt'};`. i.e. if the layout is LTR (English) font size is 10pt and if layout is RTL size is 14pt.... but when I use link, it don't recognize `#{msg['myDir']` statement... **MEANS I have to make two css file?** – Fahim Parkar Jun 03 '13 at 08:21
  • 1
    :( I have posted question... let see if there is any solution... http://stackoverflow.com/questions/16892722/how-to-load-new-css-on-every-page – Fahim Parkar Jun 03 '13 at 08:30
1

Actually, all you need to do is create a folder under webapp/resources/css/mystyle.css where mystyle.css is your css file.

Then in your jsf file, just put

<h:outputStylesheet name="css/mystyle.css" />

JSF will knows and load your css file correctly without the RES_NOT_FOUND error.

PS. this has been tested with primefaces jsf 2.2

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
hengsok
  • 255
  • 3
  • 8