简体   繁体   English

ui:composition和ui之间的区别:Facelets中的装饰

[英]Difference between ui:composition and ui:decorate in Facelets

What are the differences between ui:composition and ui:decorate in Facelets ? ui:compositionui:decorate之间有什么区别ui:decorate Facelets中的ui:decorate Both seem to support ui:define as child tags . 两者似乎都支持ui:define为子标签。 In what cases would you use each of these ? 在什么情况下你会使用这些?

Anything outside <ui:composition> tag is disregarded. <ui:composition>标记之外的任何内容都会被忽略。 This isn't true for <ui:decorate> , which is thus beneficial as "template-in-template". 对于<ui:decorate> ,情况并非如此,因此它有益于“模板中的模板”。

How that makes sense can maybe be better understood by looking at some real world examples in the below answers: 通过查看以下答案中的一些真实世界示例,可以更好地理解这有何意义:

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. 正如文档所述: http//docs.oracle.com/cd/E17802_01/j2ee/javaee/javaserverfaces/2.0/docs/pdldocs/facelets/ui/decorate.html装饰标签与组成相同,唯一的区别这就是ui:decorate不会忽略标签之外的内容,当你想要制作一个区域或页面部分的模板时,这可能很有用。

For example, ui:composition is useful when you want to make a template of the general look of your application. 例如,当您想要创建应用程序的一般外观模板时,ui:composition非常有用。 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. 使用decorate标签,由于标签外部的内容未被删除,您可以制作内容区域内部分的模板。

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). 然后在内容部分内部,您可以在创建表单时使用装饰器标记,然后使所有表单具有相同的外观(例如,标题,组件区域和按钮区域)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM