2012-09-05 41 views
16

我使用JSF/Facelets的一個項目工作的CSS文件不被使用的認可。我想在View XHTML上做一些CSS更改,但是當我在我的Tomcat服務器中部署我的Web應用程序時,什麼也沒有發生。我嘗試了很多技巧,但我得到了相同的結果。JSF/Facelets的:<:outputStylesheet H>標籤

不管怎麼說,這是我的 「styles.css的」:

body { width: 750px; } 

#header 
{ 
width:    100%; 
font-size:   36px; 
font-weight:  bold; 
line-height:  48px; 
background-color: navy; 
color:    white; 
} 

#footer 
{ 
width:    100%; 
font-weight:  bold; 
background-color: navy; 
color:    white; 
} 

這是主模板 「Template.html」 包括 「header.html中」 和 「Footer.html」,在這裏我把我的「 styles.css的」使用標籤:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" 
xmlns:f="http://java.sun.com/jsf/core" 
xmlns:h="http://java.sun.com/jsf/html" 
xmlns:ui="http://java.sun.com/jsf/facelets"> 
<head> 
<h:outputStylesheet name="css/styles.css" /> 
    <!-- i've also tried this one, using the "library" attribute --> 
    <!-- 
    <h:outputStylesheet library="css" name="styles.css" /> 
    --> 
</head> 
<h:body> 
<h:panelGroup id="page" layout="block"> 

    <h:panelGroup id="header" layout="block"> 
     <ui:insert name="header"> 
      <ui:include src="Header.html" /> 
     </ui:insert> 
    </h:panelGroup> 

    <h:panelGroup id="container" layout="block"> 
     <h:panelGroup id="content" layout="block"> 
      <ui:insert name="content">CONTENT</ui:insert> 
     </h:panelGroup> 
    </h:panelGroup> 

    <h:panelGroup id="footer" layout="block"> 
     <ui:insert name="footer"> 
      <ui:include src="Footer.html" /> 
     </ui:insert> 
    </h:panelGroup> 

</h:panelGroup> 

</h:body> 
</html> 

ANF終於在這裏是我的 「Main.xhtml」,其中包括模板 「Template.html」:

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<ui:composition xmlns="http://www.w3.org/1999/xhtml" 
xmlns:f="http://java.sun.com/jsf/core" 
xmlns:h="http://java.sun.com/jsf/html" 
xmlns:ui="http://java.sun.com/jsf/facelets" 
xmlns:a4j="http://richfaces.org/a4j" 
xmlns:rich="http://richfaces.org/rich" template="Template.html"> 
<h:body> 
    <ui:define name="content"> 
     <h:form> 
      <h:inputText title="inputText"></h:inputText> 
      <h:commandButton value="OK"></h:commandButton> 
     </h:form> 
    </ui:define> 
</h:body> 
</ui:composition> 

在此先感謝:)

+1

可以ü請驗證您的瀏覽器,你的CSS具有b個een加載。 – Abhi

+1

我該如何檢查?! – ayoubuntu

+1

在瀏覽器中右鍵單擊頁面,*查看源代碼*和/或在Chrome/IE9/Firebug中按F12,然後選中「網絡」部分。 – BalusC

回答

44

<h:outputStylesheet>(和<h:outputScript>)需要一個<h:head>,但你有一個<head>。相應地修復它。

<h:head> 
    <h:outputStylesheet name="css/styles.css" /> 
</h:head> 

此外,你需要確保css/styles.css文件被放置在公共web內容的/resources子文件夾。

WebContent 
|-- resources 
| `-- css 
|   `-- styles.css 
: 

至於你嘗試使用library屬性,請謹慎使用,使用library="css"是在此方面不完全正確的。另請參見:What is the JSF resource library for and how should it be used?

+0

是的,我以前檢查這一點,我已經把我的styles.css在同一路徑爲u說:的WebContent /資源/ CSS/Styles.css中 – ayoubuntu

+0

你也看到我的答案的第一部分? – BalusC

+0

在樹中,不應該是'WebContent/resources/css/styles.css'而不是'WebContent/resources/css/style.css'? – user454322

-3

添加資源文件夾中的的WebContent下

和內部資源創建CSS文件夾

然後訪問一樣,你沒這個

h:outputStylesheet library="css" name="myNewStylesFile.css" target="head"h:head部分文件加

+3

我downvoted,因爲我認爲這是垃圾郵件,這是一樣的BalusC的回答3年後回答的話被刪除。 –