2016-11-21 58 views
0

我想從Facelets繼承基礎模板,我不知道該怎麼做; 我在同一個文件夾中有兩個文件:base.xhtml和login.xhtml我想要從base.xhtml繼承的login.xhtml,我應該包括任何庫的簡單繼承?所有我想要的是覆蓋login.xhtml上的標題標籤和body標籤;Facelets繼承

base.xhtml:

<?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> 

回答

0

模板頁面,即通常template_name.xhtmlWEB-INF文件夾內,可能是一個新創建的文件夾下的你,是這樣的:

--WEB-INF 
    |--templates 
     |--template.xhtml 

模板.xhtml:

<?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

<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標籤不會採取帳戶的任何的標籤。