问题描述
我想构建一个自定义的JSF组件。现在我从oracle上读了一些文档,看了几个代码示例。问题是我有点困惑:
似乎有两种方法可以使用JSF 2.0+构建自定义组件。据我所知,自JSF 2.0以来我可以使用这些复合组件来构建我自己的组件。
但与Classical组件相比,它们有任何缺点吗? / p>
当我使用Compisite Components时,我的组件会变得相当复杂吗?除了向下兼容性之外?
例如,我的Component将在java中有一些工作,这可能与Composite Components有关吗?
如果复合组件很有用您希望通过纯XML表示将一堆密切相关的现有标记/组件/ HTML表示为单个可重用组件。
自定义当没有标准JSF标记/组件可用于实现该要求时,组件将是唯一的方法。例如。 < input type =file>
,< input type =range>
等请注意,只要需要,这样的自定义组件就可以在复合中使用。
完全有道理,对吧?
您可以创建一个所谓的支持组件类,扩展 UINamingContainer
(或者至少实现 NamingContainer
)并通过< cc:interface componentType>
将其绑定到组合。 。
但请注意,有时复合组件不合适,您需要创建标签文件。例如,当您想要一个自定义且可重复使用的< h:column>
时。
另见:
i want to build a custom JSF Component. Now i read some docs from oracle and saw a few code Examples. The problem is i am a bit confused:
It seems there are two ways to build a custom component with JSF 2.0+. As far as i understood since JSF 2.0 i can use these Composite Components to build my own component.
But do they have any disadvantages compared to the "Classical" Component ?
My Component will be rather complex do i loose anything (beside downwards compability) when i use Compisite Components ?
For example my Component will have some work todo in java, is this possible with Composite Components ?
A composite component is useful if you want to represent a bunch of closely related existing tags/components/HTML as a single and reuseable component by pure XML means.
A custom component would be the only way when there are no standard JSF tags/components available to achieve the requirement. E.g. <input type="file">
, <input type="range">
, etc. Note that such a custom component can in turn be used in a composite, whenever desireable.
Makes totally sense, right?
You can create a so-called "backing component" class extending UINamingContainer
(or at least implementing NamingContainer
) and bind it to the composite by <cc:interface componentType>
. You can find several examples in my answers here.
Do however note that sometimes a composite component isn't suitable, you'd need to create a tag file instead. For example when you want to have a custom and reuseable <h:column>
.
See also:
这篇关于什么是JSF自定义复合组件与自定义经典组件之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!