JSF / Facelets:无法使用< h:outputStylesheet>识别CSS文件。标签 [英] JSF/Facelets : CSS file is not being recognized using <h:outputStylesheet> tag

查看:127
本文介绍了JSF / Facelets:无法使用< h:outputStylesheet>识别CSS文件。标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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,其中我使用标签:

 <!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/>
<! - 我也试过这个,使用库属性 - >
<! -
< h:outputStylesheet library =cssname =styles.css/&
- >
< / head>
< h:body>
< h:panelGroup id =pagelayout =block>

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

< h:panelGroup id =containerlayout =block>
< h:panelGroup id =contentlayout =block>
< ui:insert name =content> CONTENT< / ui:insert>
< / h:panelGroup>
< / h:panelGroup>

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

< / h:panelGroup>

< / h:body>
< / html>


$ b

Anf终于这里是我的Main.xhtml,其中包含模板Template.html p>

 <?xml version =1.0encoding =UTF-8?& 
<!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // ENhttp://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/richtemplate =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> (and < 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在此上下文中并不完全正确。另请参阅:什么是JSF资源库for和如何使用?


I'm working on a project using JSF/Facelets. I want to do some CSS changes on my View XHTML, but nothing happen when i deploy my web application in my Tomcat Server. I've tried many tricks but i've got the same result.

Anyway, here's my "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;
}

And this is the main template "Template.html" including "Header.html" and "Footer.html", where i put my "styles.css" using the tag :

<!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 finally here's my "Main.xhtml" which include the template "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>

Thanks in advance :)

解决方案

The <h:outputStylesheet> (and <h:outputScript>) requires a <h:head>, but you've there a <head>. Fix it accordingly.

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

Further, you need to ensure that the css/styles.css file is been placed in the /resources subfolder of the public webcontent.

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

As to your attempt to use the library attribute, be careful with this, using library="css" isn't entirely correct in this context. See also: What is the JSF resource library for and how should it be used?

这篇关于JSF / Facelets:无法使用&lt; h:outputStylesheet&gt;识别CSS文件。标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆