JavaServer Faces (JSF) Interview Questions & Answers

4 avg. rating (80% score) - 1 votes

JavaServer Faces (JSF) Interview Questions & Answers

Expertise in JavaServer Faces (JSF)?  Need job? JavaServer Faces (JSF) technology is the specification used for building component-based interfaces for web applications. Component centric approach simplifies development of the java web user interface. The UI interface can be used by corporate developers and web designers. This is the reason behind the demand for the employment seekers looking for JavaServer Faces. The companies are now looking for the web developers with the knowledge in JavaServer Faces. If your web developer looking to enhance your career options by learning JavaServer Faces job interview questions and answers at wisdom jobs portal can be a good pathway. The interview questions framed here will help you gain the required subjects expert tricks to get through an interview.

JavaServer Faces (JSF) Interview Questions

JavaServer Faces (JSF) Interview Questions
    1. Question 1. What Is Jsf (or Javaserver Faces)?

      Answer :

      A server side user interface component framework for Java technology-based web applications. JavaServer Faces (JSF) is an industry standard and a framework for building component-based user interfaces for web applications. 

      JSF contains an API for representing UI components and managing their state; handling events, server-side validation, and data conversion; defining page navigation; supporting internationalization and accessibility; and providing extensibility for all these features. 

    2. Question 2. What Are The Advantages Of Jsf?

      Answer :

      The major benefits of JavaServer Faces technology are:

      • JavaServer Faces architecture makes it easy for the developers to use. In JavaServer Faces technology, user interfaces can be created easily with its built-in UI component library, which handles most of the complexities of user interface management.
      • Offers a clean separation between behavior and presentation.
      • Provides a rich architecture for managing component state, processing component data, validating user input, and handling events.
      • Robust event handling mechanism.
      • Events easily tied to server-side code.
      • Render kit support for different clients.
      • Component-level control over statefulness.
      • Highly 'pluggable' - components, view handler, etc.
      • JSF also supports internationalization and accessibility.
      • Offers multiple, standardized vendor implementations.

    3. Question 3. What Are Differences Between Struts And Jsf?

      Answer :

      In a nutshell, Faces has the following advantages over Struts:

      • Eliminated the need for a Form Bean
      • Eliminated the need for a DTO Class
      • Allows the use of the same POJO on all Tiers because of the Backing Bean

      The primary advantages of Struts as compared to JavaServer Faces technology are as follows: 

      1. Because Struts is a web application framework, it has a more sophisticated controller architecture than does JavaServer Faces technology. It is more sophisticated partly because the application developer can access the controller by creating an Action object that can integrate with the controller, whereas JavaServer Faces technology does not allow access to the controller. In addition, the Struts controller can do things like access control on each Action based on user roles. This functionality is not provided by JavaServer Faces technology.
      2. Struts includes a powerful layout management framework, called Tiles, which allows you to create templates that you can reuse across multiple pages, thus enabling you to establish an overall look-and-feel for an application.
      3. The Struts validation framework includes a larger set of standard validators, which automatically generate both server-side and client-side validation code based on a set of rules in a configuration file. You can also create custom validators and easily include them in your application by adding definitions of them in your configuration file.

      The greatest advantage that JavaServer Faces technology has over Struts is its flexible, extensible UI component model, which includes: 

      1. A standard component API for specifying the state and behavior of a wide range of components, including simple components, such as input fields, and more complex components, such as scrollable data tables. Developers can also create their own components based on these APIs, and many third parties have already done so and have made their component libraries publicly available.
      2. A separate rendering model that defines how to render the components in various ways. For example, a component used for selecting an item from a list can be rendered as a menu or a set of radio buttons.
      3. An event and listener model that defines how to handle events generated by activating a component, such as what to do when a user clicks a button.
      4. Conversion and validation models for converting and validating component data.

    4. Question 4. What Are The Available Implementations Of Javaserver Faces?

      Answer :

      The main implementations of JavaServer Faces are:

      •Reference Implementation (RI) by Sun Microsystems.
      •Apache MyFaces is an open source JavaServer Faces (JSF) implementation or run-time.
      •ADF Faces is Oracle’s implementation for the JSF standard.

    5. Question 5. What Typical Jsf Application Consists Of?

      Answer :

      A typical JSF application consists of the following parts:

      •JavaBeans components for managing application state and behavior.
      •Event-driven development (via listeners as in traditional GUI development).
      •Pages that represent MVC-style views; pages reference view roots via the JSF component tree.

    6. Question 6. What Is A Javaserver Faces Application?

      Answer :

      JavaServer Faces applications are just like any other Java web application. They run in a servlet container, and they typically contain the following:

      • JavaBeans components containing application-specific functionality and data.
      • Event listeners.
      • Pages, such as JSP pages.
      • Server-side helper classes, such as database access beans.

      In addition to these items, a JavaServer Faces application also has:

      • A custom tag library for rendering UI components on a page.
      • A custom tag library for representing event handlers, validators, and other actions.
      • UI components represented as stateful objects on the server.
      • Backing beans, which define properties and functions for UI components.
      • Validators, converters, event listeners, and event handlers.
      • An application configuration resource file for configuring application resources.

       

    7. Question 7. What Is Managed Bean?

      Answer :

      JavaBean objects managed by a JSF implementation are called managed beans. A managed bean describes how a bean is created and managed. It has nothing to do with the bean's functionalities

    8. Question 8. What Is Backing Bean?

      Answer :

      Backing beans are JavaBeans components associated with UI components used in a page. Backing-bean management separates the definition of UI component objects from objects that perform application-specific processing and hold data.

           The backing bean defines properties and handling-logics associated with the UI components used on the page. Each backing-bean property is bound to either a component instance or its value. A backing bean also defines a set of methods that perform functions for the component, such as validating the component's data, handling events that the component fires and performing processing associated with navigation when the component activates.

    9. Question 9. What Are The Differences Between A Backing Bean And Managed Bean?

      Answer :

      Backing Beans are merely a convention, a subtype of JSF Managed Beans which have a very particular purpose. There is nothing special in a Backing Bean that makes it different from any other managed bean apart from its usage.

    10. Question 10. What Makes A Backing Bean Is The Relationship It Has With A Jsf Page; It Acts As A Place To Put Component References And Event Code.

      Answer :

      Backing Beans :

      • A backing bean is any bean that is referenced by a form.
      • Backing Beans should be defined only in the request scope.

      Managed Beans :

      • A managed bean is a backing bean that has been registered with JSF (in faces-config.xml) and it automatically created (and optionally initialized) by JSF when it is needed.
      • The advantage of managed beans is that the JSF framework will automatically create these beans, optionally initialize them with parameters you specify in faces-config.xml,
      • The managed beans that are created by JSF can be stored within the request, session, or application scopes.

               Backing Beans should be defined in the request scope, exist in a one-to-one relationship with a particular page and hold all of the page specific event handling code.In a real-world scenario, several pages may need to share the same backing bean behind the scenes.A backing bean not only contains view data, but also behavior related to that data.

       

    11. Question 11. What Is View Object?

      Answer :

      A view object is a model object used specifically in the presentation tier. It contains the data that must display in the view layer and the logic to validate user input, handle events, and interact with the business-logic tier. The backing bean is the view object in a JSF-based application. Backing bean and view object are interchangeable terms.

       

       

    12. Question 12. What Is Domain Object Model?

      Answer :

      Domain object model is about the business object and should belong in the business-logic tier. It contains the business data and business logic associated with the specific business object.

    13. Question 13. What Is The Difference Between The Domain Object Model And A View Object?

      Answer :

      In a simple Web application, a domain object model can be used across all tiers, however, in a more complex Web application, a separate view object model needs to be used. Domain object model is about the business object and should belong in the business-logic tier. It contains the business data and business logic associated with the specific business object. A view object contains presentation-specific data and behavior. It contains data and logic specific to the presentation tier.

    14. Question 14. What Do You Mean By Bean Scope?

      Answer :

      Bean Scope typically holds beans and other objects that need to be available in the different components of a web application.

       

    15. Question 15. What Are The Different Kinds Of Bean Scopes In Jsf?

      Answer :

      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.

    16. Question 16. What Is The Difference Between Jsp-el And Jsf-el?

      Answer :

      SP-EL :

      • In JSP-EL the value expressions are delimited by ${…}.
      • The ${…} delimiter denotes the immediate evaluation of the expressions, at the time that the application server processes the page.

      JSF-EL :

      • In JSf-EL the value expressions are delimited by #{…}.
      • The #{…} delimiter denotes deferred evaluation. With deferred evaluation ,the application server retains the expression and evaluates it whenever a value is needed.

       

    17. Question 17. What Are The Main Tags In Jsf?

      Answer :

      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. Question 18. How Do You Declare The Managed Beans In The Faces-config.xml File?

      Answer :

      The bean instance is configured in the faces-config.xml file:
        <managed-bean>
      <managed-bean-name>login</managed-bean-name>
      <managed-bean-class>com.developersBookJsf.loginBean</managed-bean-class>
      <managed-bean-scope>request</managed-bean-scope>
        </managed-bean>
      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. Question 19. How To Declare The Message Bundle In Jsf?

      Answer :

      We can declare the message bundle in two ways: 
      (Let’s assume com.developersBookJsf.messages is the properties file)
      1.  The simplest way is to include the following elements in faces-config.xml file:
         <application>
      <resource-bundle>
      <base-name>com.developersBookJsf.messages</base-name>
      <var>message</var>
      </resource-bundle>
          </application>
      2.  Alternatively, you can add the f:loadBundle element to each JSF page that needs access to the bundle:
         <f:loadBundle baseName = “com.developersBookJsf.messages” var=”message”/>

    20. Question 20. How To Declare The Page Navigation (navigation Rules) In Faces-config.xml File?

      Answer :

      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:
        <naviagation-rule>
          <from-view-id>/index.jsp</from-view-id>
          <navigation-case>
      <from-outcome>login</from-outcome>
      <to-view-id>/welcome.jsp</to-view-id>
          </navigation-case>
        </naviagation-rule>
      This declaration states that the login action navigates to /welcome.jsp, if it occurred inside /index.jsp.

    21. Question 21. What If No Navigation Rule Matches A Given Action?

      Answer :

      If no navigation rule matches a given action, then the current page is redisplayed.

       

    22. Question 22.  what Are The Jsf Life-cycle Phases?

      Answer :

      The six phases of the JSF application lifecycle are as follows (note the event processing at each phase):

      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

       

    23. Question 23. Explain Briefly The Life-cycle Phases Of Jsf?

      Answer :

      1.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. 
      2. 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. 
      3. Process validations :   In this phase, each component will have its values validated against the application's validation rules.
      4. Update model values:   In this phase JSF updates the actual values of the server-side model ,by updating the properties of your backing beans.
      5. Invoke application :   In this phase the JSF controller invokes the application to handle Form submissions.
      6. Render response :   In this phase JSF displays the view with all of its components in their current state.

       

    24. Question 24. What Does It Mean By Render Kit In Jsf?

      Answer :

      A render kit defines how component classes map to component tags that are appropriate for a particular client. The JavaServer Faces implementation includes a standard HTML render kit for rendering to an HTML client.

    25. Question 25. Is It Possible To Have More Than One Faces Configuration File?

      Answer :

      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

       

    26. Question 26. What Is Javaserver Faces Event And Listener Model?

      Answer :

      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.

    27. Question 27. What Is Javaserver Faces Conversion Model?

      Answer :

      A mechanism for converting between string based markup generated by Java Server Faces UI components and server side Java objects

    28. Question 28. What Is Javaserver Faces Ui Component Class?

      Answer :

      A JavaServer Faces class that defines the behavior and properties of a JavaServer Faces UI component.

    29. Question 29. What Is Javaserver Faces Expression Language?

      Answer :

      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.

       

    30. Question 30. What Is Javaserver Faces Navigation Model?

      Answer :

      A mechanism for defining the sequence in which pages in a JavaServer Faces application are displayed.

    31. Question 31. What Is Javaserver Faces Technology?

      Answer :

      A framework for building server ­side user interfaces for Web applications written in the Java programming language.

    32. Question 32. What Is Javaserver Faces Ui Component?

      Answer :

      A user interface control that outputs data to a client or allows a user to input data to a JavaServer Faces application.

    33. Question 33. What Is Javaserver Faces Validation Model?

      Answer :

      A mechanism for validating the data a user inputs to a JavaServer Faces UI component.

    34. Question 34. What Is The Difference Between Jsp And Jsf?

      Answer :

      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 alidation, 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.

    35. Question 35. What Is Render Kit In Jsf?

      Answer :

      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 its 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.

    36. Question 36. How Does Jsf Depict The Mvc (model View Controller) Model?

      Answer :

      The data that is manipulated in form or the other is done by model. The data presented to user in one form or the other is done by view. JSF is connects the view and the model. View can be depicted as shown by: 
      <h:inputText value="#{user.name}"/> 
      JSF acts as controller by way of action processing done by the user or triggering of an event. For ex. 
      <h:commandbutton value="Login" action="login"/> 
      this button event will triggered by the user on Button press, which will invoke the login Bean as stated in the faces-config.xml file. Hence, it could be summarized as below: User Button Click -> form submission to server ->; invocation of Bean class ->; result thrown by Bean class caught be navigation rule ->; navigation rule based on action directs to specific page.

    37. Question 37. What Does It Mean By Rendering Of Page In Jsf?

      Answer :

      Every JSF page as described has various components made with the help of JSF library. JSF may contain h:form, h:inputText, h:commandButton, etc. Each of these are rendered (translated) to HTML output. This process is called encoding. The encoding procedure also assigns each component with a unique ID assigned by framework. The ID generated is random.

       

    38. Question 38. How To Pass A Parameter To The Jsf Application Using The Url String?

      Answer :

      if you have the following URL: http://your_server/your_app/product.jsf?id=777, you access the passing parameter id with the following lines of java code: 
      FacesContext fc = FacesContext.getCurrentInstance(); 
      String id = (String) fc.getExternalContext().getRequestParameterMap().get("id"); 
      From the page, you can access the same parameter using the predefined variable with name param. For example, 
      <h:outputText value="#{param['id']}" /> 
      Note: You have to call the jsf page directly and using the servlet mapping.

       

    39. Question 39. How To Add Context Path To Url For Outputlink?

      Answer :

      Current JSF implementation does not add the context path for outputLink if the defined path starts with '/'. To correct this problem use #{facesContext.externalContext.requestContextPath} prefix at the beginning of the outputLink value attribute. For ForExample:
      <h:outputLink value=”#{facesContext.externalContext.requestContextPath}/myPage.faces”> 

    40. Question 40. How To Get Current Page Url From Backing Bean?

      Answer :

      1. You can get a reference to the HTTP request object via FacesContext like this: 

      FacesContext fc = FacesContext.getCurrentInstance(); 
      HttpServletRequest request = (HttpServletRequest) fc.getExternalContext().getRequest(); 

      and then use the normal request methods to obtain path information. Alternatively, context.getViewRoot().getViewId(); 

      will return you the name of the current JSP (JSF view IDs are basically just JSP path names).

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

JavaServer Faces (JSF) Tutorial