ArticleslgStudy

science

Facelets

Facelets is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Facelets rather than just read about it. In short: In computing, Facelets is an open-source Web template system under the Apache license and the default view handler technology (aka view declaration language) for Jakarta Faces (JSF; formerly Jakarta Server Faces and JavaServer Faces). The language requires valid input XML documents to work.

Key takeaways

  • Facelets belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Facelets to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Facelets from memory before moving on to harder problems.

Reference excerpt

In computing, Facelets is an open-source Web template system under the Apache license and the default view handler technology (aka view declaration language) for Jakarta Faces (JSF; formerly Jakarta Server Faces and JavaServer Faces). The language requires valid input XML documents to work. Facelets supports all of the JSF UI components and focuses completely on building the JSF component tree, reflecting the view for a JSF application. Although both JSP and Faces technologies have been improved to work better together, Facelets eliminates the issues noted in Hans Bergsten's article "Improving JSF by Dumping JSP" Facelets draws on some of the ideas from Apache Tapestry, and is similar enough to draw comparison. The project is conceptually similar to Tapestry's, which treats blocks of HTML elements as framework components backed by Java classes. Facelets also has some similarities to the Apache Tiles framework with respect to support templating as well as composition. Facelets was originally created by Jacob Hookom in 2005 as a separate, alternative view declaration language for JSF 1.1 and JSF 1.2 which both used JSP as the default view declaration language. Starting from JSF 2.0, Facelets has been promoted by the JSF expert group to be the default view declaration language. JSP has been deprecated as a legacy fall back.

Element conversion In Facelets, templates tags from a tag library can be entered in two forms: directly as a qualified xml element or indirectly via the jsfc attribute on an arbitrary non-qualified element. In the latter case the Facelet compiler will ignore the actual element and will process the element as if it was the one given by the jsfc attribute. The following example shows the direct usage of qualified tags:

Using the jsfc attribute, the same code can also be expressed as the example given below:

The above code can be viewed in a browser, and edited with conventional WYSIWYG design tools. This is not possible when directly using the qualified tags. Nevertheless, directly using qualified tags is the most popular way of using Facelets in practice and is the style most used in books and examples.

Templating Facelets provides a facility for templating. A Facelets file can reference a master template and provide content for the placeholders this master template defines. The file that references such a template is called the template client. Template clients themselves can again be used as a template for other template clients and as such a hierarchy of templates can be created. The following shows an example of a simple master template: templates/master_template.xhtml

The above code contains a default HTML 'frame' and a single placeholder called body_content. A template client can use this template as follows: template_client.xhtml

The above code makes use of the template /templates/master_template.xhtml and provides content for the placeholder in that template. The final result will be a page called template_client.xhtml that has the content of /templates/master_template.xhtml, but with <ui:insert name="body_content"/> replaced by 'This is a template client page that uses the master template.'.

Content re-use In addition to templating, Facelets provides support for re-use by letting the user include content that resides in a different file. Including such content can be done in three different ways:

Referencing a file Custom tags Composite components

Referencing a file The simplest way to include the content of another Facelet is referencing it by name using the <ui:include> tag. This causes the content in the referenced file to be directly included in the calling Facelet by the Facelets compiler. Besides re-using content at multiple locations, this can be used to break down a large Facelet into smaller parts. The following shows an example: templates/master_template.xhtml

html_head.xhtml

Custom tags Facelets supports indirection for including content via custom tags. Such a custom tag can be associated with a Facelet in a taglib file. Occurrences of that tag will then be replaced with the content of the associated Facelet. The following shows an example of this: templates/master_template.xhtml

The code above uses the tag <my:spacer> to mark the point in the Facelet where content is to be inserted. Such a tag has to be declared in a Taglib file where it can be associated with a Facelet as follows: example.taglib.xml

The following shows an example of what the actual content Facelet could look like: spacer.xhtml

Composite components Besides including content directly, Facelets provides the composite component mechanism that makes content available as a first-class JSF component. Composite components do not need to be declared in a Taglib file, but instead have to be put in a special directory. By convention the content is then automatically assigned a namespace and a tag name. The namespace is constructed of the fixed string 'http://java.sun.com/jsf/composite/' concatenated with the directory name in which the content file resides relative to the 'resources' directory. The tag name becomes the file name without the .xhtml suffix. The following shows an example of this: resources/my/spacer.xhtml

The above Facelet is automatically available as a component in namespace 'http://java.sun.com/jsf/composite/my' and tag name 'spacer'

Parameterized includes To customize included content, Facelets allows parameters to be used. Via those parameters, objects can be passed into the included content, where they can be used as variables. For the <ui:include> mechanism the <ui:param> can be used for this, while for the custom tags and composite components, normal tag attributes can be used. Composite components require parameters to be declared in their interface section, while for custom tags there is no such requirement and values provided for arbitrary attributes are made available as variables with the same name as said attribute.

See also

JavaServer Faces

References

Bibliography

External links "Introduction to Facelets" Chapter 8 of The Jakarta EE Tutorial Facelets Developer Documentation at the Wayback Machine (archived 2016-12-31) Hightower, Richard (February 21, 2006). "Facelets fits JSF like a glove". Java. DeveloperWorks. IBM. Archived from the original on 2021-02-24. Facelets Home Page at the Wayback Machine (archived 2017-04-04)

Worked examples

Example 1 — a first encounter with Facelets

Start with the simplest possible case. Write down what Facelets claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Facelets before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Facelets ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Facelets

In research
Facelets appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Facelets in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Facelets is common in secondary-school and first-year university syllabi. It links to neighbouring topics Java (programming language), so understanding it makes those chapters shorter.
In everyday life
Look for Facelets outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Facelets” →

How to study Facelets in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Facelets means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Facelets out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Facelets in simple terms?

In computing, Facelets is an open-source Web template system under the Apache license and the default view handler technology (aka view declaration language) for Jakarta Faces (JSF; formerly Jakarta Server Faces and JavaServer Faces). The language requires valid input XML documents to work.

Why does Facelets matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Facelets?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Facelets.

Tags

  • Java (programming language)

Keep exploring