JSF模板未应用

时间:2010-09-02 18:31:45

标签: templates jsf

我创建了模板(template.xhtml),它位于应用程序的根上下文中。 我想将它应用于驻留在'public'文件夹中的页面(newTemplateClient.xhtml)。 所以newTemplateClient.xhtml看起来像这样:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns="http://www.w3.org/1999/xhtml"
            template="./../template.xhtml">
                            .
                            .
                            .

我在index.xhtml中有这个页面的链接:

<h:link outcome="/public/newTemplateClient" value="Login"/>

<h:commandLink action="/public/newTemplateClient?faces-redirect=true" value="Login"/>

<h:commandLink action="/public/newTemplateClient" value="Login"/>

只有最后才有效。当我使用前两页显示但未应用模板时。 因此,只有在重定向页面而不转发页面时,它才有效。为什么呢?

提前致谢

好的,似乎应用了模板,但css文件却没有。我正在使用NetBeans向导来创建模板和模板客户端。 css文件位于/ resources / css /目录中。 它们是从template.xhtml引用的:

`

<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><ui:insert name="title">template</ui:insert></title>
</h:head>

<h:body>

    <div id="top">
        <ui:insert name="top">Top</ui:insert>
    </div>

    <div id="content" class="center_content">
        <ui:insert name="content">Content</ui:insert>
    </div>

    <div id="bottom">
        <ui:insert name="bottom">Bottom</ui:insert>
    </div>

</h:body>

`

如何以其他方式引用该css文件? 文件夹结构:

Root
  public
    newClientTemplate.xhtml
  template.xhtml
  index.xhtml

1 个答案:

答案 0 :(得分:3)

好的问题解决了。 解决方案是使用:

<h:outputStylesheet name"css/default.css"/>
<h:outputStylesheet name"css/cssLayout.css"/>

相反:

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