【问题标题】:CSS and JS library lost while refresh page in JSF application using facelets使用 facelets 在 JSF 应用程序中刷新页面时 CSS 和 JS 库丢失
【发布时间】:2012-08-10 09:58:30
【问题描述】:

为什么我在刷新 JSF 中有模板的页面时会丢失所有 CSS 和 JS?

我的模板:

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html">

    <h:head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <link href="./resources/css/default.css" rel="stylesheet" type="text/css" />
        <link href="./resources/css/cssLayout.css" rel="stylesheet" type="text/css" />
        <title>Facelets Template</title>
    </h:head>

    <h:body>


        <div id="top" class="top">
            <ui:insert name="top">
                <h:form>
                    <h:commandButton value="Home" action="#{auth.goHome()}"/>
                    <h:commandButton value="Logout" action="#{auth.logout}"/>
                </h:form>
            </ui:insert>
        </div>
        <div>
            <div id="left">
                <ui:insert name="left">Left</ui:insert>
            </div>
            <div id="content" class="left_content">
                <ui:insert name="content">Content</ui:insert>
            </div>
        </div>
    </h:body>

</html>

子页面:

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
        <ui:composition template="/contentTemplate.xhtml" >

        </ui:composition>
    </h:body>
</html>

**GET http://localhost:11032/Integration/Common/resources/css/default.css 404 (Not Found) welcome.xhtml:5
GET http://localhost:11032/Integration/Common/resources/css/cssLayout.css 404 (Not Found)**

【问题讨论】:

    标签: jsf-2 facelets


    【解决方案1】:

    开始尝试替换

    <link href="./resources/css/default.css" rel="stylesheet" type="text/css" /> 
    

    (和其他 css)与

    <h:outputStylesheet name="css/default.css" target="head" /> (do same for the other css)
    

    如果这不起作用,您可以尝试使用#{facesContext.externalContext.requestContextPath}

    <link href="#{facesContext.externalContext.requestContextPath}/css/default.css" rel="styleSheet" type="text/css"/>     
    

    【讨论】:

      猜你喜欢
      • 2020-08-28
      • 2019-09-12
      • 2011-11-20
      • 2018-12-25
      • 2016-11-13
      • 2012-11-09
      • 1970-01-01
      • 1970-01-01
      • 2020-11-20
      相关资源
      最近更新 更多