如何在JSF中创建现有组件的组合? [英] How to create a composite of existing components in JSF?
问题描述
我想知道是否可以组成我自己的组件(或称其为Widget,Object).
I'd like to know if it's possible to compose my own component (or call it Widget, Object).
我的意思是,而不是(例如)使用h:panelGroup
和其中的h:outputLabel
,而是使用我自己的h:panelMarkzzz
作为panelGroup和outputLabel的组成.
I mean, instead of (for example) using h:panelGroup
and a h:outputLabel
inside it, make my own h:panelMarkzzz
, as a composition of panelGroup and outputLabel.
在JSF上可以吗?
推荐答案
是的,可以像这样创建现有组件的组合.
Yes, it's possible to create a composition of existing components like that.
开球示例:
/resources/foo/group.xhtml
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:cc="http://xmlns.jcp.org/jsf/composite">
<cc:interface>
<cc:attribute name="label" type="java.lang.String" required="true" />
</cc:interface>
<cc:implementation>
<h:panelGroup>
<h:outputLabel value="#{cc.attrs.label}" />
<cc:insertChildren />
</h:panelGroup>
</cc:implementation>
</html>
/test.xhtml
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:foo="http://xmlns.jcp.org/jsf/composite/foo">
<h:head>
<title>Test</title>
</h:head>
<h:body>
<foo:group label="Label value">
<h:outputText value="This will appear after label inside the panelgroup" />
</foo:group>
</h:body>
</html>
/foo
文件夹名称不受您的限制,您可以在XML名称空间中将其引用为http://xmlns.jcp.org/jsf/composite/XXX
. XHTML文件名是标记名称.
The /foo
folder name is free to your taste and you can reference it in XML namespace as http://xmlns.jcp.org/jsf/composite/XXX
. The XHTML filename is the tag name.
也就是说,复合组件具有性能影响,仅当使用简单的include或标记文件无法满足功能要求时才应使用它们.在您的特定情况下,最好改用标记文件.仅当您真正需要<cc:interface componentType="...">
时,才需要使用复合组件.
That said, composite components have performance implications and they should only be used when the functional requirement is not achievable using a simple include or tagfile. In your specific case, you'd better use a tagfile instead. A composite component is only worthy when you actually need it for the <cc:interface componentType="...">
.
- 何时使用< ui:include> ;、标记文件,复合组件和/或自定义组件?
- 我们的复合组件Wiki页面
- JSF
http://xmlns.jcp.org/jsf/composite
标记文档 - Java EE 7教程-复合组件
- Java EE 7教程-高级复合组件
- When to use <ui:include>, tag files, composite components and/or custom components?
- Our composite component wiki page
- JSF
http://xmlns.jcp.org/jsf/composite
tag documentation - Java EE 7 tutorial - Composite components
- Java EE 7 tutorial - Advanced composite components
这篇关于如何在JSF中创建现有组件的组合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!