ui:decorate 和 ui:include 之间真正的概念区别是什么? [英] What is the real conceptual difference between ui:decorate and ui:include?
问题描述
我之前发现 ui:decorate
在功能上与 ui:include
相同,除了您还可以传递 ui:param
和ui:define
到包含的文件.
It occurs ago me that ui:decorate
is functionally the same as ui:include
except that you can also pass ui:param
and ui:define
to the included file.
我疯了吗?
虽然实际上你也可以将 ui:param
传递给 ui:include
文件,但事实证明我已经在做它.也许你也可以传递一个ui:define
,我会在这里检查和编辑.
EDIT : Although in fact you can pass ui:param
to a ui:include
file too, it turns out I am already doing it. Maybe you can pass a ui:define
as well, I will check and edit here.
推荐答案
和
是
旨在允许插入用户定义的模板组件,而
旨在包括现有的和已经预定义的模板.
The main difference between <ui:include>
and <ui:decorate>
is that the <ui:decorate>
is intended to allow insertion of user-defined template components, while the <ui:include>
is intended to include an existing and already-predefined template.
这确实意味着
支持 <ui:define>
用于其主体中的用户定义模板组件,并且可以将其插入
放在模板内.
This indeed means that the <ui:decorate>
supports <ui:define>
for user-defined template components in its body and can insert it at the <ui:insert>
place inside the template.
这里有一个 - 有点笨拙的 - 示例来展示它的用途:
Here's a -somewhat clumsy- example to show where it can be used:
/WEB-INF/templates/field.xhtml
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
>
<h:outputLabel for="#{id}" value="#{label}" />
<ui:insert name="input" />
<h:message id="#{id}_message" for="#{id}" />
</ui:composition>
/page.xhtml
<h:panelGrid columns="3">
<ui:decorate template="/WEB-INF/templates/field.xhtml">
<ui:param name="label" value="Foo" />
<ui:param name="id" value="foo" />
<ui:define name="input">
<h:inputText id="foo" value="#{bean.foo}" required="true" />
</ui:define>
</ui:decorate>
<ui:decorate template="/WEB-INF/templates/field.xhtml">
<ui:param name="label" value="Bar" />
<ui:param name="id" value="bar" />
<ui:define name="input">
<h:selectBooleanCheckbox id="bar" value="#{bean.bar}" required="true" />
</ui:define>
</ui:decorate>
...
</h:panelGrid>
请注意,它可以很好地呈现面板网格的每个单元格中的组件.同样,这个特定的例子非常笨拙,我只是使用了一个 标记文件 代替.仅当它是更大的部分时,例如一个完整的形式,例如它的页眉或页脚应该是可定制的,然后
应该是合适的.
Note that it renders the components nicely in each cell of the panel grid. Again, this particular example is pretty clumsy, I'd just have used a tag file instead. Only if it was a larger section, e.g. a whole form whose e.g. its header or footer should be customizable, then an <ui:decorate>
would have been appropriate.
的另一个主要优点是它允许您使用带有模板的复合组件.另请参阅 是否可以使用模板在 JSF 2 中使用复合组件?
Another major advantage of <ui:decorate>
is that it allows you to use a composite component with a template. See also Is it possible to use template with composite component in JSF 2?
这篇关于ui:decorate 和 ui:include 之间真正的概念区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!