wood burning stoves*
The moose likes JSF and the fly likes Facelets experts please advise! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Facelets experts please advise!" Watch "Facelets experts please advise!" New topic
Author

Facelets experts please advise!

Frank Silbermann
Ranch Hand

Joined: Jun 06, 2002
Posts: 1387
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

Joined: Jun 25, 2001
Posts: 16158
    
  21

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!

Customer surveys are for companies who didn't pay proper attention to begin with.
Frank Silbermann
Ranch Hand

Joined: Jun 06, 2002
Posts: 1387
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

Joined: Jun 25, 2001
Posts: 16158
    
  21

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

Joined: Jun 06, 2002
Posts: 1387
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

Joined: Jun 25, 2001
Posts: 16158
    
  21

Nest templates all you want.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Facelets experts please advise!