Home » Java » Enterprise Java » What is JavaServer Faces (JSF) – (Part 2)

About Alex Theedom

Alex Theedom
Alex Theedom is a Senior Java Developer and has recently played a pivotal role in the architectural design and development of a microservice based, custom built lottery and instant win game platform. Alex has experience of Java web application development in a diverse range of fields including finance, e-learning, lottery and software development. He is the co-author of Professional Java EE Design Patterns and many articles.

What is JavaServer Faces (JSF) – (Part 2)

Facelets Declaration Language

In part 1 I introduced the basic idea behind JavaServer Pages (JSF). In this article, I would like to introduce the Facelets declaration language.

HTML tags

The first tags we meet are the HTML tags that represent HTML elements. These are really just syntactic sugar over HTML tags such as input, radio button etc. but provide some cross-browser compatibility. You are not required to use them; so you can just use the normal HTML tags if you prefer.

<h:form>, <h:inputText>, <h:commandButton>, <h:selectOneRadio>, <h:inputTextArea>, <h:outputText>, <h:commandLink> ...

Facelets Tags

An important feature of the Facelets language is the ability to create templates for reusability and repeatability. We are provided with a selection of tags that allow this to be done in quite a logical fashion, such as the repeat tag that repeats a section code and the define tag that’s start a components definition.

<ui:composition>, <ui:insert>, <ui:repeat>, <ui:fragment>, <ui:debug>, <ui:decorate>, <ui:param>, <ui:define> ...

Core tags

At the heart of Facelets tags are the core tags. These add more functionality through converters, action listeners, validators and much more. This is where you will find functionality such as AJAX, language resource bundles and so on.

<f:convert>, <f:convertDateTime>, <f:lengthvalidate>, <f:ajax>, <f:loadBundle>, <f:selectItem>, <f:actionListener> …

CDI Scopes

And now we come to the concept of a scope. Beans are defined as having a scope. The scope of a bean determines its lifecycle. The scope also determines which clients refer to which instances of the bean. By default, beans are given the scope of dependent.

An instance of a dependent bean is never shared between different clients. It is instantiated when the object it belongs to is created and destroyed when the object it belongs to is destroyed.

New Java EE 7 scopes

In Java EE 7 some new bean scopes were introduced namely @ViewScoped, @FlowScoped and @FlowDefinition.

Briefly, ViewScoped beans share the same lifecycle as the view which initially referenced them. This is particularly useful for views that make use of AJAX. FlowScoped and FlowDefinition are used with Faces Flow which connects logically related pages together and allows the bean’s lifecycle to be defined for that collection of views.

What Next

If you want to learn more about JSF and Java EE why now take my course Learning Java Enterprise Edition. In this course, I teach you the basics of a range of Java EE APIs. If you are really serious and want to give your career a boost the following courses are just what you are looking for:

Further Reading

Want to learn more about Java EE then these articles should interest you:

Reference: Introduction to JSF (part 2) from our JCG partner Alex Theedom at the Read Learn Code blog.
(0 rating, 0 votes)
You need to be a registered member to rate this.
Start the discussion Views Tweet it!
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy

Leave a Reply

avatar

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  Subscribe  
Notify of