Facelets:只需要一个页面的标签

发布于 2024-11-30 18:17:50 字数 363 浏览 1 评论 0原文

好的,要在另一个页面中包含一个页面,我需要 标记。但是如果我只想包含页面的一部分呢?

让我解释一下: 我有一个模板,其中包含标签 和其他 标签。 页面 List.xhtml 使用此模板,当然会填充所有模板标记。现在,在另一个名为 Create.xhtml (使用相同模板)的页面中,在某个时刻,我只想放置 List.xhtml 的正文标记内容,而不是其他标记。是否可以?

谢谢您的回答。

Okay, to include a page in another page I need <ui:include src="pageName"/> tag. But if i want to include only a portion of a page?

Let me explain:
I have a template that has the tag <ui:insert name="body"/> and other <ui:insert.../> tags.
A page, List.xhtml, uses this template and, of course, fills up ALL the template tags. Now, in another page, named Create.xhtml (that uses the same template), at a certain point, i want to put ONLY the body tag content of List.xhtml, not other tags. Is it possible?

Thank you for you answers.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜光 2024-12-07 18:17:50

最简单的方法可能是将 List.xhtml 的正文部分分解为自己的 。然后您可以在需要的页面中通过 重新使用它。这将是执行此操作的“模板”方式。

或者,您可以在 body 部分之外创建一个 。这将是执行此操作的“组件”方式。两者都应该实现相同的基本目标,但组合/装饰可能更简单。

更新
示例(另请参阅此处)。

commonBody.xhtml

...
<ui:composition>
<p>This is some common body.</p>
<p><ui:insert name="dynamicBody" /></p>
</ui:composition>

List.xhtml

...
<body>
<h1>This is the List.xhtml</h1>
<ui:decorate template="commonBody.xhtml">
<ui:define name="dynamicBody">Body of List.xhtml</ui:define>
</ui:decorate>
</body>
...

会输出类似的内容

...
<body>
<h1>This is the List.xhtml</h1>
<p>This is some common body.</p>
<p>Body of List.xhtml</p>
</body>
...

Easiest might be to break out the body section of your List.xhtml into its own <ui:composition>. Then you can re-use it in with <ui:decorate> in the pages where you need it. This would be the "template" way of doing it.

Alternativly, you can create a <ui:component> out of the body section. This would be the "component" way of doing it. Both should achieve the same basic goal you have, but composition/decorate might be simpler.

UPDATE
Example (See also here).

commonBody.xhtml

...
<ui:composition>
<p>This is some common body.</p>
<p><ui:insert name="dynamicBody" /></p>
</ui:composition>

List.xhtml

...
<body>
<h1>This is the List.xhtml</h1>
<ui:decorate template="commonBody.xhtml">
<ui:define name="dynamicBody">Body of List.xhtml</ui:define>
</ui:decorate>
</body>
...

Would output something like

...
<body>
<h1>This is the List.xhtml</h1>
<p>This is some common body.</p>
<p>Body of List.xhtml</p>
</body>
...
怀中猫帐中妖 2024-12-07 18:17:50

另一种方式:

template.xhtml:

......

<ui:insert name="body"/>

......

List.xhtml:

<ui:composition xmlns=....... template="/template.xhtml">

..............

     <ui:define name="body">

          <ui:include src="ListContent.xhtml"/>

     </ui:define>

..............

</ui:composition>

ListContent.xhtml

<ui:component xmlns....>

     Content I can reuse in other pages different by List.xhtml 
     (without see List.xhtml entire content, which is the scope of this question),
     simply writing "<ui:include src="ListContent.xhtml"/>" in the target page code.

</ui:component>

希望可以帮助别人。

Another way:

template.xhtml:

......

<ui:insert name="body"/>

......

List.xhtml:

<ui:composition xmlns=....... template="/template.xhtml">

..............

     <ui:define name="body">

          <ui:include src="ListContent.xhtml"/>

     </ui:define>

..............

</ui:composition>

ListContent.xhtml

<ui:component xmlns....>

     Content I can reuse in other pages different by List.xhtml 
     (without see List.xhtml entire content, which is the scope of this question),
     simply writing "<ui:include src="ListContent.xhtml"/>" in the target page code.

</ui:component>

Hope can help someone.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文