Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Facelets experts please advise!

 
Frank Silbermann
Ranch Hand
Posts: 1407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With Facelets, can I use templates for building new templates?

Can I partially instantiate a template to create a slightly more defined template?
Can I instantiate a template with another template (e.g. using one template to decorate another)?

Suppose A, B, C, D, ... are each sections of JSF mark-up, and each `_' indicates a template <ui:insert> region.

Example 1:

Suppose I create a template (A _ B _) that leaves room for two regions to be defined.
Obviously I could use it to compose JSF pages such as A C B D and or A E B F.

Could I compose it with just C, to result in a template that defines (A C B _)?
I would use that new template to define JSF pages such as:
A C B D,
A C B F,
A C B H,
etc.

Example 2:

Suppose I have a decorator template that defines (A _ B),
and another template that defines (C _ D _J),
could I compose them to produce a template that defines (A C _ D _ B)
-- with which I could then generate such JSF pages as:

A C E D F B,
A C G D H B

while still using the original two templates to produce

A J B

and

C K D L
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18225
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure I really understood that, but there is no theoretical limit to how you can define a View comprised of nested templates.

In practice, of course, it's best to keep it simple because otherwise the resulting visual display may offend the user's eyes. And of course, don't do circular references!
 
Frank Silbermann
Ranch Hand
Posts: 1407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway wrote:I'm not sure I really understood that, but there is no theoretical limit to how you can define a View comprised of nested templates.
Is a template considered to be a kind of View when you say that -- or do you use "View" to refer only to a final JSF page definition?

In other words, suppose I have five templates that are each used hundreds of times. Among these uses, I have a dozen web pages, each of which nests the same five templates in the same way (but which differ as to the leaf facelets that are inserted).

Can I nest the five templates to create a sixth template (as distinct from nesting them in a page definition)?

That way, each of that dozen pages would just use that sixth template -- instead of constantly repeating a complex nesting.

(Sure, I could make that sixth template from scratch, but doing so would violate the DRY principle. So would repeating that same complex nesting.)
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18225
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For my purposes, the View is the entire web page and it may be composed of one or more sub-views. The sub-views may be complex controls, included templates, other Facelet composition templates, custom tags and so forth.

For the sake of visual sanity, I normally have 1 or a very small number of master templates which I then use to frame the more specific page content templates.
 
Frank Silbermann
Ranch Hand
Posts: 1407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway wrote:For my purposes, the View is the entire web page and it may be composed of one or more sub-views. The sub-views may be complex controls, included templates, other Facelet composition templates, custom tags and so forth.

For the sake of visual sanity, I normally have 1 or a very small number of master templates which I then use to frame the more specific page content templates.
And does that mean one can or cannot use templates in the definition of other templates?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18225
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nest templates all you want.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic