understand the purpose of jsf ui:composition

ぃ、小莉子 提交于 2019-11-26 14:46:40

问题


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?


回答1:


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:

  • How to include another XHTML in XHTML using JSF 2.0 Facelets?


来源:https://stackoverflow.com/questions/6525050/understand-the-purpose-of-jsf-uicomposition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!