She*_*ari 11 jsf facelets include
我有问题,包括facelet模板.我想拆分一些内容,以便我可以在其他地方重用它.
所以我改变了这段代码:
<!DOCTYPE html>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
template="/layout/template.xhtml">
<ui:define name="head">
<title>Title</title>
</ui:define>
<ui:define name="header">
<h3>Header</h3>
</ui:define>
<ui:define name="content">
<table><tr><td>table</td></tr></table>
</ui:define>
</ui:composition>
Run Code Online (Sandbox Code Playgroud)
对此:
<!DOCTYPE html>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
template="/layout/template.xhtml">
<ui:define name="head">
<title>Title</title>
</ui:define>
<ui:include src="/admin/admin_generic.xhtml"/>
</ui:composition>
Run Code Online (Sandbox Code Playgroud)
在里面admin-generic.xhtml我把代码包装在一个ui:composition中.
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:define name="header">
<h3>Header</h3>
</ui:define>
<ui:define name="content">
<table><tr><td>table</td></tr></table>
</ui:define>
</ui:composition>
Run Code Online (Sandbox Code Playgroud)
但没有显示任何内容.我只是得到一个空白页面,没有错误.使用不对ui:composition吗?我试过ui:component但但也没有帮助.
更新:根据我的Facelets要点指南,它说:
该
ui:include标签可用于包括另一Facelets的文件到您的文档.它只包含您指定的任何源文件.您可以包含任何具有ui:component或ui:composition标记的 Facelets文件(将内容修剪为自身之外)或仅包含XHTML或XML的片段.
那是怎么回事?包括在内的内容是否已被删除?如何在不修剪内容的情况下包含页面?
Bal*_*usC 11
在<ui:define>必须被放置在一个<ui:composition>或<ui:decorate> 与一个template包含适当<ui:insert>的标签.你已经把它移到<ui:composition> 没有了template.没有模板意味着没有内容.
从技术上讲,实现您的要求,您可以替换<ui:include>的<ui:insert>.
<!DOCTYPE html>
<ui:composition
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
template="template.xhtml">
<ui:define name="head">
<title>Title</title>
</ui:define>
<ui:insert />
</ui:composition>
Run Code Online (Sandbox Code Playgroud)
并宣布上述页面(我假设它somepage.xhtml)作为template在admin_generic.xhtml.
<!DOCTYPE html>
<ui:composition
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
template="somepage.xhtml">
<ui:define name="header">
<h1>Header</h1>
</ui:define>
<ui:define name="content">
<table><tr><td>table</td></tr></table>
</ui:define>
</ui:composition>
Run Code Online (Sandbox Code Playgroud)
请注意,您必须admin_generic.xhtml在浏览器中打开.如果您的意图是somepage.xhtml在浏览器中打开,那么<ui:define>真的必须留在somepage.xhtml.但是,您可以<ui:define>通过简单的方式替换身体<ui:include>.
<!DOCTYPE html>
<ui:composition
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
template="template.xhtml">
<ui:define name="head">
<title>Title</title>
</ui:define>
<ui:define name="header">
<h1>Header</h1>
</ui:define>
<ui:define name="content">
<ui:include src="admin_generic.xhtml" />
</ui:define>
</ui:composition>
Run Code Online (Sandbox Code Playgroud)
它允许<ui:composition>,所以你不一定需要把它<table>放到root.
<!DOCTYPE html>
<ui:composition
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<table><tr><td>table</td></tr></table>
</ui:composition>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10049 次 |
| 最近记录: |