2
votes

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.

2

2 Answers

2
votes

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>
...
0
votes

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.