JSF Interview Questions

Explain the way be which we can declare the Message Bundle in JSF?

Usually this can be done in two ways:
(Let’s assume com.j2eebrainJsf.messages is the properties file)
The easiest way is to include the following elements in faces-config.xml file:
Another way is that you can add the f:loadBundle element to each JSF page that needs access to the bundle:
<f:loadBundle baseName = “com.j2eebrainJsf.messages” var=”message”/>

Explain the JSF life-cycle phases?

The  main six phases that are part of the JSF application lifecycle are :
1.  Restore view
2.  Apply request values; process events
3.  Process validations; process events
4.  Update model values; process events
5.  Invoke application; process events
6.  Render response

Explain how you can declare managed beans in the faces-config.xml file?

The bean instance is configured in the faces-config.xml file:
This means: Construct an object of the class com.j2eebrainJsf.loginBean, give it the name login, and keep it alive for the duration of the request.

Explain the different kinds of Bean Scopes in JSF?

JSF supports three Bean Scopes. these are mainly :

  • Request Scope: This is for a request and gets died of when the response is sent back to the requestor.
  • Session Scope: The is for a session and is availanble till the session is ended.
  • Application Scope: The is for the entire duration of the web application. This scope is shared among Request and Session scopes

Explain the main tags that are used in JSF?

In JSF applications the JSP pages are used to represent the views JSF has a mechanism to use special tags to improve the views
For each tag there is a associated component. JSF (Sun Implementation) provides 43 tags in two standard JSF tag libraries:

  • JSF Core Tags Library.
  • JSF Html Tags Library.

Is it possible to have more than one Faces Configuration file?

We can have any number of config files. Just need to register in web.xml.
Assume that we want to use faces-config(1,2,and 3),to register more than one faces configuration file in JSF,just declare in the web.xml file

<span style="white-space: pre;">		</span>&lt;param-name&gt;javax.faces.CONFIG_FILES&lt;/param-name&gt;
<span style="white-space: pre;">		</span>&lt;param-value&gt;
<span style="white-space: pre;">			</span>/WEB-INF/faces-config1.xml,
<span style="white-space: pre;">			</span>/WEB-INF/faces-config2.xml,
<span style="white-space: pre;">			</span>/WEB-INF/faces-config3.xml
<span style="white-space: pre;">		</span>&lt;/param-value&gt;

Explain briefly the life-cycle phases of JSF?

  • Restore View : A request comes through the FacesServlet controller. The controller examines the request and extracts the view ID, which is determined by the name of the JSP page.
  • Apply request values:   The purpose of the apply request values phase is for each component to retrieve its current state. The components must first be retrieved or created from the FacesContext object, followed by their values.
  • Process validations:   In this phase, each component will have its values validated against the application’s validation rules.
  • Update model values:   In this phase JSF updates the actual values of the server-side model ,by updating the properties of your backing beans.
  • Invoke application:   In this phase the JSF controller invokes the application to handle Form submissions.
  • Render response:   In this phase JSF displays the view with all of its components in their current state.

The below diagram explains this better.