首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >因子遗传

因子遗传
EN

Stack Overflow用户
提问于 2016-11-21 21:36:31
回答 1查看 305关注 0票数 0

我想要从一个基本模板中继承base.xhtml,但我不知道该如何做;我在同一个文件夹中有两个文件: login.xhtml和login.xhtml,我希望login.xhtml从base.xhtml继承,是否应该包含任何库来进行简单的继承?我想要的只是在login.xhtml上覆盖标题标签和正文标签;

base.xhtml:

代码语言:javascript
复制
<?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">
<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><ui:insert name="titre" /></title>
        <link type="text/css" rel="stylesheet" href="resources/css/bootstrap.css"></link>
        <link type="text/css" rel="stylesheet" href="resources/css/tether.min.css"></link>
        <script type="text/javascript" src="resources/js/jquery.js"></script>
        <script type="text/javascript" src="resources/js/tether.min.js"></script> 
        <script type="text/javascript" src="resources/js/bootstrap.js"></script>
        <script type="text/javascript" src="resources/js/sortable.js"></script>

    </h:head>
    <h:body>

    </h:body>
</html>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-22 00:22:54

模板页,即template_name.xhtml通常进入WEB-INF文件夹,可能在您新创建的文件夹下,如下所示:

代码语言:javascript
复制
--WEB-INF 
    |--templates
        |--template.xhtml

template.xhtml:

代码语言:javascript
复制
<?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">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:f="http://xmlns.jcp.org/jsf/core">

    <h:head>
      <ui:insert name="tabTitle">
          Some default title
      </ui:insert>

      // normally you leave spaces for you to define external resources
      <ui:insert name="css" />
      <ui:insert name="js" />

    </h:head>
    <h:body>

      <ui:insert name="body">
           Default content
      </ui:insrt>               

    </h:body>
</html>

然后,每当您想使用上面的模板时:

some_page.xhtml

代码语言:javascript
复制
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:f="http://xmlns.jcp.org/jsf/core"

      template="/WEB-INF/templates/template.xhtml">


    // the just override any <ui:insert /> tag you want by setting the
    // name="" attribute to which ever you want to override

    <ui:define name="body">
          this will be the content that overrides your template "body", the rest will stay the same
    </ui:define>

</ui:composition>

之所以不需要其他任何东西,是因为<ui:compsition标记将不考虑它的标记的以外的任何内容。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40729836

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档