Href = "RES_NOT_FOUND" using h: outputStylesheet

I am creating a multilingual web application using JSF 2.0.

For css I used to use

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

and inside the CSS file I had

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

However, due to CSS caching, the same CSS file exists, and I get the font as 10pt continuously, even if I choose Arabic.

Therefore, I added time after CSS.

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

However, when I use this, all my CSS go for the drop ... I see the default page setting (no css is called)

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

Any idea what I'm doing wrong?

Note. I am using JSF 2.0


I also print #{language.myTimeinMill} inside the body and see a different time each time.

+4
source share
2 answers

The only way I can see is to use a simple <link> .

There is no way to use <h:outputStylesheet /> to add a parameter to the URL. One answer on this question no longer works 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 the "name" attribute and nested content. Ignoring attached content.

However, 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> 
+2
source

In fact, all you have 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 library="css" name="mystyle.css" /> 

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

PS. this has been tested with jsf 2.2 interfaces

+2
source

Source: https://habr.com/ru/post/1484020/


All Articles