JSF Interview Questions
- What is JSF (Java Server Faces)?
JavaServer Faces (JSF) is an application framework containing a rich and robust set of APIs and JSP custom tag libraries to simplify creating user interfaces for web based Java applications. Set of APIs represent user interface components and are responsible for managing their state, handling events, validating input. APIs also define page navigation, internationalization and accessibility. JSF includes JSP custom tag library for including JSF interface within a JSP page.So JSF offers a flexible and extensible architecture that makes easy creating reusable, complex server side UI components without limiting developers to a particular mark-up language, protocol, or client device by combining the UI component functionality with custom renderers. Here extensible means additional functionality can be given on the top of JSF core i.e. we can customize the functionality and reusable stands for being able to add and reuse components many times in the page.
In the past many web development frameworks came in to existence founded on servlet and jsp. Struts emerged as a standard web application framework. It became framework of choice because it came early in the market and provided necessary features at the time but competitors continued providing additional features that struts lacks. So it became necessary for java to advent new standard framework with a powerful component model. This was the reason for developing JSF technology. So main purpose of developing JSF was to create a collection of APIs for the UI components with the capacity to manage their states, handle events and validation. So JSF can be think of a combination of two frameworks, Struts and Swing. Struts is a popular open source JSP-based Web application framework and Swing is a standard Java user interface framework for desktop applications. Like Struts, JSF provides Web application lifecycle management through a controller servlet (FacesServlet) and like Swing, JSF provides a rich component model complete with event handling and component rendering. JSF also ensures that applications are well designed with greater maintainability by integrating the well established Model-View-Controller (MVC) design pattern into its architecture. So it clearly separates behavior (Model) and presentation (View) in an application. This separation enables a wide range of users Page authors( web-page designers), Application developers, Component writers, Application architects , Tool vendors and allows members of team to focus on their own work only , resulting in division of labor and shorter development cycle. JSF has been developed by Java Community Process(JCP) that is a community of web application experts from different groups like Jakarta Struts, Oracle, Sun, IBM, ATG etc. They all collectively worked together to take the best from existing technologies and removed problems. So their collective effort brought a new technology named Java Server Faces (JSF).
Facts about JSF can be summarized as below :- JSF is standard web UI server side component framework for Java.
- Built on top of Servlet API.
- UI components are stored on the server.
- Easy use of third party components.
- Event driven programming model.
- Events generated by user are handled on the server.
- Navigation handling.
- Can automatically synchronize UI components .
- JSF supports multiple client devices.
- JSF has extensible architecture.
- International language support.
- Extensive tool support (Sun, Oracle , IBM etc.).
- Rapid application development approach.
- What is the significance of MVC model in JSF?
JSF ensures that applications are well designed with greater maintainability by integrating the well established Model-View-Controller (MVC) design pattern into its architecture. So it clearly separates behavior (Model) and presentation of data (View) in an application. UI components represent View (Typically in JSP), managed beans represent Model and FacesServlet is the Controller in the JSF framework. All the requests are handled by this controller. Any request passes through and examined by FacesServlet that calls various actions on the model (managed beans). The separation of behavior and presentation enables a wide range of users Page authors( web-page designers), Application developers, Component writers, Application architects , Tool vendors and allows members of team to focus on their own work only , resulting in division of labor and shorter development cycle.
- Which plays role of controller in JSF?
JSF integrates the well established Model-View-Controller (MVC) design pattern into its architecture. The purpose of MVC is to separate data (Model) and presentation of data (View) in an application. User requests are handled centrally by the controller that might result in changes in the model and views. In JSF, UI components represent View layer and managed beans represent Model. FacesServlet is the Controller in the JSF framework. All the requests are handled by this controller. Any request passes through and examined by FacesServlet that calls various actions on the model (managed beans).