JSF 模板,每个页面包含一段 HTML
我不知道如何在我的网络应用程序的每个页面中包含一段 HTML(比如一个小表格
)。
假设这是我想要包含的表格,所以我制作了一个模板:
<?xml version ... ?>
<!DOCTYPE ...">
<html xmlns="... all the required namespaces ...">
<head>
</head>
<body>
<table>
<tr><td>first</td><td>second</td><td>third</td><td>...</td></tr>
</table>
</body>
</html>
然后我有了使用它的代码:
<?xml version ...?>
<!DOCTYPE ...">
<html xmlns="... all required namespaces ...">
<body>
<h3>Will this be displayed?</h3>
<ui:composition template="tableTemplate.xhtml">
<h4>Will this?</h4>
</ui:composition>
</body>
</html>
我在浏览器上看到的页面是:
<html xmlns ...>
<head>
</head>
<body>
<table>
<tr><td>first</td><td>second</td><td>third</td><td>...</td></tr>
</table>
</body>
</html>
所以有表格,但其余的都丢失了!
I can't figure out how to include a piece of HTML (say a little table
) in each of the pages of my web app.
Say this is the table I want to include, so I made a template:
<?xml version ... ?>
<!DOCTYPE ...">
<html xmlns="... all the required namespaces ...">
<head>
</head>
<body>
<table>
<tr><td>first</td><td>second</td><td>third</td><td>...</td></tr>
</table>
</body>
</html>
then I have the code that uses it:
<?xml version ...?>
<!DOCTYPE ...">
<html xmlns="... all required namespaces ...">
<body>
<h3>Will this be displayed?</h3>
<ui:composition template="tableTemplate.xhtml">
<h4>Will this?</h4>
</ui:composition>
</body>
</html>
the page that I get on the browser is:
<html xmlns ...>
<head>
</head>
<body>
<table>
<tr><td>first</td><td>second</td><td>third</td><td>...</td></tr>
</table>
</body>
</html>
so there is the table but all the rest is missing!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在主模板中,您需要使用
来声明将插入模板定义的位置。template.xhtml
在模板客户端中,您需要使用
来定义要插入到模板中声明的位置的模板定义。page.xhtml
周围不需要 HTML。无论如何,他们都会被忽视。只是不要在那里放置任何 HTML,这只会浪费空间并且让您自己感到困惑。当您在浏览器中打开
page.xhtml
时,渲染输出中将出现以下内容:In the master template, you need to use
<ui:insert>
to declare the place where the template definitions will be inserted.template.xhtml
In the template client, you need to use
<ui:define>
to define the template definitions which are to be inserted in the places declared in the template.page.xhtml
No HTML around
<ui:composition>
is necessary. They will be ignored anyway. Just don't put any HTML there, that's only waste of space and confusing for yourself.When you open
page.xhtml
in the browser, the following will end up in the rendered output:尝试
并在您的 tableTemplate.xhtml 中
TRY
and in your tableTemplate.xhtml