Difference between ui:composition and ui:decorate in Facelets
Asked Answered
G

2

15

What are the differences between ui:composition and ui:decorate in Facelets ? Both seem to support ui:define as child tags . In what cases would you use each of these ?

Gouveia answered 26/10, 2012 at 17:53 Comment(0)
C
13

Anything outside <ui:composition> tag is disregarded. This isn't true for <ui:decorate>, which is thus beneficial as "template-in-template".

How that makes sense can maybe be better understood by looking at some real world examples in the below answers:

Coach answered 26/10, 2012 at 19:2 Comment(2)
what you mean by "template-in-template" ? also can you give some contrived example to demonstrate the power of ui:decorate over ui:composition ?Gouveia
You can nest <ui:decorate> in another <ui:composition> or even <ui:decorate>. This isn't true for <ui:composition> as it disregards/ignores/removes anything outside the tag. The given links contain detailed real world examples.Coach
J
1

As the documentation says: http://docs.oracle.com/cd/E17802_01/j2ee/javaee/javaserverfaces/2.0/docs/pdldocs/facelets/ui/decorate.html the decorator tags is identical to the composition, the only difference it's that ui:decorate don't disregard al the content outside of the tag, which can be useful when you want to make a template of an area or section of the page.

For example, ui:composition is useful when you want to make a template of the general look of your application. As it removes the content outside of the tag, the template attribute really defines the general look of areas of your application.

With the decorate tags, as the content outside the tag is not removed, you can make templates of the section that goes inside a content area.

An example could be an use of use composition templates to define header, menu, footer and content sections.

Then inside the content sections you can make use of the decorator tag when you want to make a form, and then make all your forms have the same look (with a title, components area, and buttons area for example).

Jailer answered 9/11, 2013 at 13:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.