5

I am starting development on a new web application which uses JSF 2 as the view technology. I have no prior experience with JSF and am a bit confused about the concepts.
I read some documentation on JSF and the main idea was that it a component based framework. Applications are built from components.

But now there are two ways of creating a component, as I understood:
1. composition - a collection of components which can be included in a page
2. composite - a new component that encapsulate some components and exposes an interface to users

What is the basic rule in choosing between them?
For example, I want to show a list of products to an user. For this list I should create my own component which I add to the main layout, to separate the view code. So should this list be a composition or composite?

I hope somebody can help me clear up this basic stuff.

Thanks in advance,

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
ats
  • 73
  • 1
  • 7

2 Answers2

6

Go for composition (templating) when you want a reuseable template which you normally include only once in the main view. E.g. header, menu, footer, single table, etc. Go for composite component when you want a reuseable component with a bean-value-binding which you can include as many as you want in the main view. E.g. a group of label, input and message components (although a tag file is often better for this).

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Do you have a reference to some documentation that supports your comment here?Seeing as composition was really the only re-use option in jsf 1.x and composite has only been introduced in 2.x, why would the behavior of composition change? We were using (probably abusing) composition extensively in a project, then tried to run in 2.0 and found everything using composition was quite broken. – digitaljoel May 25 '10 at 21:26
0

Perhaps the following link to the JEE 6 Tutorial would help.

Determining Whether You Need a Custom Component or Renderer

MathiasJ
  • 1,661
  • 1
  • 14
  • 20