Professional Java Server Faces Interview Questions & Answers:
1. Do you know what is AJAX and what problem does it solve?
Ajax is a set of client side technologies that allows asynchronous communication between client and web server. In synchronous communication, complete round trip happens with each request/response action event when small data of the page to be refreshed. Ajax has solved this problem of posting entire information every time through asynchronous communication.
XmlHttpRequest is the basic fundamental behind Ajax. This allows browser to communicate with server without making post backs.
The JavaServer Faces page is similar to JSP page in terms of their life cycle.
When user makes a request, the life cycle of a JSF web application, starts.
Several tasks are performed by JSF when a user submits a page. These tasks include data validation, data type conversion, etc.
A JSF application supports two kinds of responses and two kinds of requests.
Faces response:
Request processing life cycle creates a servlet response by the execution of the Render Response Phase of the.
Non-Faces response:
A servlet response is not created by the execution of the render response phase.
Faces request:
A servlet request is sent from a previously generated Faces response. E.g.: The request URI in the form submission from a JSF UI component, identifies the JSF component tree to use for processing the request.
Non-Faces request:
A servlet request is sent to an application component, such as a servlet or JSP page, rather than directed to a JavaServer Faces component tree.
The steps in the life cycle of a JSF application are:
1. Restore View Phase
2. Apply Request Value Phase
3. Process Validations Phase
4. Update Model Value Phase
5. Invoke Application Phase
6. Render Response Phase
3. What is rendering of page in JSF?
A JSF page has components that are made with the help of JSF library. The JSF components lke h:form, h:inputText, h:commandButton, etc., are rendered / translated to HTML output. This process is known as encoding. Encoding also assigns a unique id to a component by the framework and the ids are generated at random.
JavaServer Faces (JSF) is a user interface framework for building web applications that run on the server side and render the user interface back to the client.
It lets you develop tools that simplify coding web-based Java applications.
Users of your JSF-based web applications can use the wide range of user actions made available by JSF controls. More features can be offered more conveniently than they can be with a standard HTML front end. JSF requires little more effort than an ordinary JSP configuration but still has more benefits.
5. Do you know how to declare the Navigation Rules for JSF?
A navigation rule specifies the JSF implementation which page need to send back to the browser after submitting a form. For instance, after the successful login, the page should to Main page or to return on the same login page. The following code snippet describes this.
<navigation-rule>
<from-view-id>/login.jsp</from-view-id>
<navigation-case>
<from-outcome>login</from-outcome>
<to-view-id>/main.jsp<to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>fail</from-outcome>
<to-view-id>/login.jsp<to-view-id>
</navigation-case>
</navigation-rule>
from-outcome to be match with action attribute of the command button of the login.jsp as:
<h:commandbutton value="Login" action="login"/>
Secondly, it should also match with the navigation rule in face-config.xml as
<managed-bean>
<managed-bean-name>user</managed-bean-name>
<managed-bean-class>core.jsf.LoginBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
In the UI component, to be declared / used as:
<h:inputText value="#{user.name}"/>
value attribute is the name property of the user bean.
6. Tell me how the components of JSF are rendered?
JSF libraries need to be added in an application.
On the .jsp page, a tag library needs to be added:
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
In an XML style:
<?xml version="1.0"?>
<jsp:root version="2.0" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html">
The JSF components can be accessed using the prefix attached.
In an IDE, JSF can be added easily. However, when working without them the faces-config.xml needs to be updated and populated with classes i.e. Managed Beans between the following tags
<faces-config> </faces-config>
7. Explain how JSF different from conventional JSP?
JSP is good for mixing static content and dynamic content pulled from resources made available by other parts of the application; for instance, a servlet.
JSP's main mission in life is to generate a response to a request; a JSP page is processed in one pass from top to bottom, with JSP action elements processed in the order in which they appear in the page.
However, JSF has a much more complex lifecycle.
JSF components get created, process their input (if any), and then render themselves.
For JSF to work well, these three things must happen separately in a well-defined order, but when JSF is used with JSP, they don't.
Instead, the component creation and rendering happens in parallel, causing all kinds of problems.
Ajax support can be added to the following panel components.
<hx:panelActionbar>
<hx:panelBox>
<hx:panelDialog>
<hx:panelFormBox>
<h:panelGrid>
<h:panelGroup>
<hx:panelLayout>
<hx:panelMenu>
<hx:panelSection>
To add Ajax support to a JSF page:
1. Drag a panel component from the palette onto the JSP.
2. Drag additional components (for example an input component) from the palette onto the panel component.
3. In the properties view, select the panel component tag. Select the Ajax tab.
4. On the Ajax tab, select the Allow Ajax updates checkbox.
5. Select the type of Ajax request that you want to use:
o Refresh - A GET request for the same page.
o Submit - A POST request for the same page.
o External - A GET request for a different page.
6. Configure the request parameters.
o hx:ajaxRefreshRequest
o hx:ajaxExternalRequest
Note: If the component, the value of which needs to be used as a parameter is contained by a data table, you must manually add $$AJAXROW$$component client id> to the parameter set. Where <component client id> is a client ID of the component whose value you want to send as the parameter.
9. Can you explain JSF Ajax components?
The custom web tier components for JSF can be developed using AJAX along with JSF. Using JSF the state of an application, event handling, input validation and page navigation tasks can be done for user interface components. AJAX technology is used for client side Java Script leverage in order to provide richer and more responsive user experience.
To implement the JSF component for spell check text area, the following tag is used.
<jcr: spellCheckTextArea cols="30" rows="15" value="# {user.interests}" />
This component extends HtmlInputTextArea provides a simple AJAX-enabled spell checking facility
JSF developed based on MVC design pattern. Therefore, the applications can be scaled better and well maintained. It is standardized pattern driven by Java Community Process. The advantage of JSF is both Java web user interface and a framework which perfectly fits with MVC. The presentation and behaviour of a web application is a clean separation. UI can be created by web page authors and the business logic can be utilized by managed beans. There are controllers which can be used to perform user actions.
https://InterviewQuestionsAnswers.ORG.