Whats the difference between JSF Custom Composite Components vs Custom Classic Components

若如初见. 提交于 2019-12-03 07:54:01

问题


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 ?


回答1:


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:

  • When to use <ui:include>, tag files, composite components and/or custom components?


来源:https://stackoverflow.com/questions/12847003/whats-the-difference-between-jsf-custom-composite-components-vs-custom-classic-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!