2016-11-21 6 views
0

Facelets로 기본 템플릿을 상속하고 싶습니다. 어떻게해야할지 모르겠습니다. 동일한 폴더에 두 개의 파일이 있습니다. 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 태그 아무것도 외부을 계정에 걸릴하지 않기 때문에 다른 필요한 이유는 아무것도 없다 태그의