Loading…
JSF Interview Questions

An Overview of JSF

JSF is known as Java Server Faces, and it is an MVC web-based framework. It mainly simplifies User Interface (UI) construction for server-based applications. The UI components are reusable in a page in JSF. It provides a set of standard UI components and gives an Application Programming Interface (API) for the developing elements. All the popular JSF interview questions and answers have been put together which will be handy if you want to crack an interview.

Advantages of JSF

  • The UI components of JSF are reusable.
  • JSF allows transferring data quickly between the UI components.
  • The efforts of creating and maintaining applications are reduced by JSF.
  • UI state is managed across multiple server requests.
  • The architecture of JSF is easy to use by the developers.
  • In JSF a clear separation is there between behavior and presentation.

These top JSF Interview Questions will be helpful in clearing job interviews and getting a promotion at work.

JSF majorly provides:

  • A set of core libraries.
  • A set of UI components- HTML input elements.
  • JSF has multiple rendering capabilities which enable JSF UI components to render them that depends differently on the client types.
  • The base UI components are extended to make additional UI component libraries or existing extended components.
Development History

JSF was developed in the year 2001 and was written in Java.

All the popular JSF interview questions and answers have been put together which will be handy if you want to crack an interview. This will be helpful in clearing job interviews and getting a promotion at work.

JSF Interview Questions and answers

Looking for a new job? Do not miss to read our JSF Interview Questions and answers. Whether you are a fresher or an experienced, these questions and answers that can help you to crack your interview.

When there is a need to attach multiple listeners, a JSF tag for value change listeners and the action listeners are used to attach more than one listener to the element. When you make use of the tag syntax, you specify the class which implements the listener interface.

JSF provides special tags in order to create a standard layout of a web application called Facelets tags. These tags provide a flexible approach to manage common parts of the multiple pages in one place. You need to make use of the following namespaces in the URL HTML mode: Xmls- “http://www.w3.org/1999/xhtml.”

The Render kit refers to the collection of a renderer which renders the Java faces. These are kits specialized for some clients to perform specific purposes. A typical Java server renders more than one renderkit instances applications.

Yes, there can be many faces in config.xml files in JSF.

JSF provides a standard HTML tag library. These tags are rendered into the corresponding HTML tag.

S.no JSF 1.0 JSF 2.0
1. It is the first release of the JSF specifications It is the second release of the JSF specifications
2. Does not support the usage of annotations JSF 2 supports the ajax features
3. The API had a lot of bugs It is totally redesigned and used as an MVC framework.

The Value expression usually fetches a value or a set of values. These expressions can be categorized into rvalue and Ivalue expressions. The Ivalue expressions can read as well as write data whereas on the other hand rvalue expression can only read the data.

The method expression allows the users to involve a public method of the bean which returns the result that is important for validation of the data component and for handling the events.

The full form of JSF is Java Server Faces. This is a server-side component based on the user interface framework. It is mainly used for developing web applications. It gives a programming model which is well-defined. It has rich API and tag libraries. JSF 2 is the latest version which is using Facelets as a default templating system.

The primary purpose of JSF is to make the construction process of the user interface simple. This UI is used for server-based applications, and the components can be reusable in a page. It connects the UI widgets with data sources. It provides the standard UI components and API (Application Programming Interface) majorly for developing components.

The JSF life cycle begins when the client makes an HTTP request for a particular page. It generally ends when there is a server respond with the page. This life cycle is divided into two primary phases: Execute Phase and Render Phase.

The new features of JSF 2.0 are:
  • A mechanism is provided which can easily access persistent store.
  • Page loading action is there in JSF 2.0.
  • Standard HTML Renderkit has strategic additions like a tree, data picker, file upload components, and tab view.
  • It gives allowance for partial tree transversal.
  • Build the tree and render the tree processes are two different lifecycle phases.
The difference between struts2 and JSF are:
S.no Struts2 JSF
1. It is an action based framework. It is a component-based framework.
2. It is accessible to tag libraries because the component is less. It has a lot of component libraries.
3. The action framework in struts2 is thinner. The component framework in JSF is not thin.

Managed Bean: It is a basic bean java class of JSF. This java bean is being managed by the JSF framework. It consists of getter and setter methods and business logic. Managed beans generally work for UI component as a model. It can be easily accessed from the JSF page. Backing Bean: It is a subpart of the managed bean. It contains all the properties of UI components in a JSF page.

This bean is used in UI conversion, component validations, and event handling. Almost all the features of UI components binds with a backing bean in JSF page.

Resource Bundling mainly stores the UI date, label, status messages, and UI textual elements separately in the properties file and does not do any hardcoding in the page. It is one of the most convenient methods. Resource bundles are stored in .inproperties file extension because they are key-value pair of strings. This maintenance keeps the messages in a single place.

@ViewScoped: -As long as the user is interacting with a similar JSF view, the beans are alive. It is usually created on an HTTP request. The bean gets destroyed when the user post-backs to a different view.

@SessionScoped:- Beans are there as long as HTTP session lives. This gets created with the first HTTP request. This bean is destroyed when the HTTP session is invalidated.

@CustomScoped:- This bean is there when it enters in the map of custom. It is created for a particular scope live.

@RequestScoped: -Beans are there as long as the HTTP request-response lives. This usually gets created when an HTTP is requested. It gets destroyed when the HTTP request is over.

The attributes of tag in JSF are accepted, class, enctype, id, lang, rendered, onclick and onsubmit.

The tag which is used to upload a file on the website in JSF is . JSF uses HTML element of file type. This tag is used for the file to get it as input.

The difference between JSF and JSP are:
S.no JSF JSP
1. The full form of JSF is Java Server Faces, and it is a web-based application. The full form of JSP is Java Server Pages, and it is a Java-based technology.
2. The file extension of JSF is .jsf The file extension of JSP is .jsp
3. In JSF the tag attributes are dynamic in nature and are mapped automatically. Tag attributes have to be declared in the TSD file.
The different types of JSF events are:
  • Post Construct Application Event:- It fires when the application begins. It is used for performing tasks related to initialization after an application has started.
  • Pre Destroy Application Event:- It fires when an application is about to close. It performs all kinds of clean-up tasks before the application gets closed.
  • PreRender View Event:- It fires when the JSF page is about to get displayed. It is used for user authentication. It gives restricted access to JSF view.

JSF is having different types of bean scopes like @RequestScoped, @NoneScoped, @ViewScoped, @SessionScoped, @ApplicationScoped and @CustomScoped.

A h: output Text Tag in JSF is used for rendering a plain text. The presence of "styleClass", "style", "dir" or "lang" attributes are present, then it renders a "span" element. If the "styleClass" attribute is present, then it renders its value as the value of the "class" attribute.

The Backing bean is similar to the Managed bean in JSF. The difference in the two merely pertains to the usage of the two.

S.no Backing Bean Managed Bean
1. A backing bean is referred to by its form The managed bean is a backing bean which has been registered with the JSF. It gets automatically created and optimized by the JSF.
2. The Backing Beans should be defined in the request scope only The Managed beans are created by the JSF, and it can be stored within the session, request or application scope.

The programmer should create a new XML file and put the managed beans detail inside and declare the XML file in the javas.faces.CONFIG_FILES. This is done to initialize the parameters which are there inside the WEBINF/web.xml. file.

You can declare the message bundle in two ways. The first way which is the simplest way is to state the message bundle by a supply file name faces-config.xml in the Web INF category. Another way is to use a global resource bundle declaration. You can add the f: load Bundle element to each element.

Ask Question