2016-11-21 3 views
0

私はFaceletsを使って基本テンプレートを継承したいと思います。 私は同じフォルダに2つのファイルを持っています:base.xhtmlとlogin.xhtml login.xhtmlをbase.xhtmlから継承したいのですが、単純継承のためのライブラリを含めるべきですか?私が望むのは、login.xhtmlのtitleタグと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.xhtmlは通常、おそらくあなたによって新たに作成したフォルダの下に、WEB-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タグは何ものアカウントに反映されませんので、他に必要とされる理由は何もありませんそのタグの