html - JSF/小面 : CSS file is not being recognized using <h:outputStylesheet> tag

标签 html css jsf facelets

我正在使用 JSF/Facelets 开发一个元素。我想对我的 View XHTML 做一些 CSS 更改,但是当我在我的 Tomcat 服务器中部署我的 Web 应用程序时没有任何反应。我尝试了很多技巧,但得到了相同的结果。

无论如何,这是我的“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>

提前致谢:)

最佳答案

<h:outputStylesheet> (和 <h:outputScript> )需要一个 <h:head> , 但你有一个 <head> .相应地修复它。

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

此外,您需要确保 css/styles.css文件被放置在 /resources公共(public)网络内容的子文件夹。

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

关于您尝试使用 library属性,小心这个,使用 library="css"在这种情况下并不完全正确。另请参阅:What is the JSF resource library for and how should it be used?

关于html - JSF/小面 : CSS file is not being recognized using <h:outputStylesheet> tag,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12281839/

相关文章:

internet-explorer - 脚本5009 : 'Primefaces' is undefined in IE9 - Error disappears after reloading

angularjs - JSF 的 Facelets 和 AngularJS ng-view

javascript - Angular 输入绑定(bind)两个字段

java - JSF - 变量中的托管 bean?

javascript - 将答案添加到peerJS脚本

css - 防止子 div 扩展 flexbox div

html - 每次刷新时页面加载不同

html - Bootstrap container 或者 Well keep the well one size and enlarge text

html - 将 HTML &lt;title&gt; 标签的方向更改为从右到左

javascript - 缩略图刷新时禁用scrollIntoView()的自动垂直滚动