Top 25 JSF Interview Questions
1. What is the JSF?
JavaServer Faces(JSF) is a framework for building web-based user interface in Java. Unlike Swing, JSF provides widgets like buttons, hyperlinks, checkboxes, etc. in different ways. It has extensible facilities for validating inputs and converting objects to and from strings for display.
JSF is the Java answer to Microsoft ASP.NET’s Web Forms. ASP.Net is roughly equivalent to the Servlet and JSP
2. What is JavaServer Faces event and listener model?
A mechanism for determining how events emitted by JavaServer Faces UI components are handled. This model is based on the JavaBeans component event and listener model.
3. What is JavaServer Faces conversion model?
A mechanism for converting between string-based markup generated by JavaServer Faces UI components and server-side Java objects.
4. What is JavaServer Faces UI component class?
A JavaServer Faces class that defines the behavior and properties of a JavaServer Faces UI component.
5. What is JavaServer Faces expression language?
A simple expression language used by a JavaServer Faces UI component tag attributes to bind the associated component to a bean property or to bind the associated component’s value to a method or an external data source, such as a bean property.
Unlike JSP EL expressions, JavaServer Faces EL expressions are evaluated by the JavaServer Faces implementation rather than by the Web container.
6. What is JavaServer Faces navigation model?
A mechanism for defining the sequence in which pages in a JavaServer Faces application are displayed.
7. What is JavaServer Faces Technology?
A framework for building server-side user interfaces for Web applications written in the Java programming language.
8. What is JavaServer Faces UI component?
A user interface control that outputs data to a client or allows a user to input data to a JavaServer Faces application.
9. What is JavaServer Faces validation model?
A mechanism for validating the data a user inputs to a JavaServer Faces UI component.
10. What is the difference between JSP and JSF?
JSP simply provides a Page which may contain markup, embedded Java code, and tags which encapsulate more complicated logic / html. JSF may use JSP as its template, but provides much more.
This includes validation, rich component model and lifecycle, more sophisticated EL, separation of data, navigation handling, different view technologies (instead of JSP), ability to provide more advanced features such as AJAX, etc.
11. What are tags in JSF?
JSF application typically uses JSP pages to represent views. JSF provides useful special tags to enhance these views. Each tag gives rise to an associated component. JSF (Sun Implementation) provides 43 tags in two standard JSF tag libraries: 1. JSF Core Tags Library 2. JSF Html Tags Library Even a very simple page uses tags from both libraries. These tags can be used adding the following lines of code at the head of the page. <%@ taglib uri=”http://java.sun.com/jsf/core “ prefix=”f” %> (For Core Tags) <%@ taglib uri=”http://java.sun.com/jsf/html “ prefix=”h” %> (For Html Tags)
12. What is JSF life cycle and its phases?
The series of steps followed by an application is called its life cycle. A JSF application typically follows six steps in its life.
1. Restore view phase
2. Apply request values phase
3. Process validations phase
4. Update model values phase
5. Invoke application phase
6. Render response phase
13. What is Render Kit in JSF?
Component classes generally transfer the task of generating output to the renderer. All JSF components follow it. Render kit is a set of related renderers. javax.faces.render.RenderKit is the class which represents the render kit. The default render kit contains renderers for html but it’s up to you to make it for other markup languages. Render kit can implement a skin (a look & feel).
Render kit can target a specific device like phone, PC or markup language like HTML, WML, SVG. This is one of the best benefit of JSF because JSF doesn’t limit to any device or markup.
14. What do you mean by Bean Scope?
Bean Scope typically holds beans and other objects that need to be available in the different components of a web application.
15. What are the different kinds of Bean Scopes in JSF?
JSF supports three Bean Scopes. viz.,
Request Scope: The request scope is short-lived. It starts when an HTTP request is submitted and ends when the response is sent back to the client.
Session Scope: The session scope persists from the time that a session is established until session termination.
Application Scope: The application scope persists for the entire duration of the web application. This scope is shared among all the requests and sessions.
17. What are The main tags in JSF?
JSF application typically uses JSP pages to represent views. JSF provides useful special tags to enhance these views. Each tag gives rise to an associated component. JSF (Sun Implementation) provides 43 tags in two standard JSF tag libraries:
JSF Core Tags Library.
JSF Html Tags Library.
18. How do you declare the managed beans in the faces-config.xml file?
The bean instance is configured in the faces-config.xml file:
login
com.developersBookJsf.loginBean
request
This means: Construct an object of the class com.developersBookJsf.loginBean, give it the name login, and keep it alive for the duration of the request.
19. How to declare the Message Bundle in JSF?
We can declare the message bundle in two ways:
(Let’s assume com.developersBookJsf.messages is the properties file)
20. How to declare the page navigation (navigation rules) in faces-config.xml file ?
Navigation rules tells JSF implementation which page to send back to the browser after a form has been submitted.
We can declare the page navigation as follows:
/index.jsp
login
/welcome.jsp
This declaration states that the login action navigates to /welcome.jsp, if it occurred inside /index.jsp.