Search code examples
htmlcssjsfjsf-2stylesheet

href="RES_NOT_FOUND" using h:outputStylesheet


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.


Solution

  • 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>