understand the purpose of jsf ui:composition
Asked Answered
E

1

10

What is the usefulness of the following?

<ui:composition template="template.xhtml">;

"In a template client page using <ui:composition>, anything outside of the bounds of a tag is ignored and is not included in the rendered output" (JavaServerFaces 2.0, the complete reference, pg.61)

Since everything outside <ui:define> is ignored, why put anything there? Nothing has to be put outside the <ui:define>.

But doing so, all I get will be the template itself with only some "variable" parts filled.

It seems not to be this big deal. Another thing I don't understand, is that template attribute of composition element is optional. What does it represent a template client without the reference to a template?

Explorer answered 29/6, 2011 at 17:51 Comment(0)
B
13

What is the usefulness of the following?

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

With this you can declare to use a basic template which has placeholders to insert template definitions. This is more useful than doing it the other way round. You would need to include for example the header, footer and/or menu in every page again and again. With a template you don't need to do this. It just goes in the template.


"In a template client page using <ui:composition>, anything outside of the bounds of a tag is ignored and is not included in the rendered output" (JavaServerFaces 2.0, the complete reference, pg.61)

Since everything outside is ignored, why put anything there? Nothing has to be put outside the <ui:define>.

You don't need to do so. Why would you? Okay maybe the basic tutorial does that, but that's just for demonstration purposes. "This will not be included in the rendered output" and so on. On the other hand, if you happen to use a visual editor, then the content outside <ui:composition> will be regarded. See also Is there a way to run a JSF page without building the whole project?


Another thing I don't understand, is that template attribute of composition element is optional. What does it rapresent a template client without the reference to a template?

A simple include file which you can include by <ui:include>.

See also:

Brookite answered 29/6, 2011 at 19:58 Comment(3)
ok. say that I have to insert a little table in each page of my web site. How am I supposed to do?Explorer
You can choose between <ui:composition template> or <ui:include>. With the <ui:composition template> you've the advantage that you can undoubtely refactor more other duplicated tags into the template, such as <!DOCTYPE html>, <html>, <h:head> <h:body> and others.Brookite
Since I tried and I can't figure out how to accomplish this, I've put another ad-hoc question: #6528301Explorer

© 2022 - 2024 — McMap. All rights reserved.