The largest Interview Solution Library on the web


Interview Questions
« Previous | 0 | 1 | 2 | 3 | 4 | Next »

22.  What are the JSF life-cycle phases?

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. Explain briefly the life-cycle phases of JSF?


    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. What does it mean by render kit in JSF?

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


	<context-param>
		<param-name>javax.faces.CONFIG_FILES</param-name>
		<param-value>
			/WEB-INF/faces-config1.xml,
			/WEB-INF/faces-config2.xml,
			/WEB-INF/faces-config3.xml 
		</param-value>
	</context-param>

26. How JSF different from conventional JSP / Servlet Model?

JSF much more plumbing that JSP developers have to implement by hand, such as page navigation and validation. One can think of JSP and servlets as the “assembly language� under the hood of the high-level JSF framework.

27. How the components of JSF are rendered An Example?

In an application add the JSF libraries. Further in the .jsp page one has to add the tag library like:

<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>

Or one can try XML style as well:

<?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">

Once this is done, one can access the JSF components using the prefix attached. If working with an IDE (a.k.a Integrated Development Environment) one can easily add JSF but when working without them one also has to update/make the faces-config.xml and have to populate the file with classes i.e. Managed Beans between

<faces-config> </faces-config> tags 

28. How do I configure the configuration file?

The configuration file used is our old web.xml, if we use some IDE it will be pretty simple to generate but the contents will be something like below: com.sun.faces.verifyObjects false com.sun.faces.validateXml true javax.faces.STATE_SAVING_METHOD client Faces Servlet javax.faces.webapp.FacesServlet 1 Faces Servlet /faces/* 30 index.jsp The unique thing about this file is ?servlet mapping?. JSF pages are processed by a servlet known to be part of JSF implementation code. In the example above, it has extension of .faces. It would be wrong to point your browser to http://localhost:8080/MyJSF/login.jsp, but it has to be http://localhost:8080/MyJSF/login.faces. If you want that your pages to be with .jsf, it can be done with small modification :-), Faces Servlet *.jsf

29.How does JSF depict the MVC (a.k.a Model View Controller) model?

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: JSF acts as controller by way of action processing done by the user or triggering of an event. For ex. , 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.

30.What does it mean by rendering of page in JSF?

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.

31.How to pass a parameter to the JSF application using the URL string?

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, Note: You have to call the jsf page directly and using the servlet mapping.

32.How to add context path to URL for outputLink?

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 example:

33.How to get current page URL from backing bean?

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

34.How to access web.xml init parameters from java code?

You can get it using externalContext getInitParameter method. For example, if you have: connectionString jdbc:oracle:thin:scott/tiger@aarifm:1521:O901DB You can access this connection string with: FacesContext fc = FacesContext.getCurrentInstance(); String connection = fc.getExternalContext() .getInitParameter("connectionString");

35.How to access web.xml init parameters from jsp page?

You can get it using initParam pre-defined JSF EL variable. For example, if you have: productId 011D You can access this parameter with #{initParam[‘productId’]} . For example: Product Id:

36. How to terminate the session?

In order to terminate the session you can use session invalidate method. This is an example how to terminate the session from the action method of a backing bean:
public String logout() { FacesContext fc = FacesContext.getCurrentInstance(); HttpSession session = (HttpSession) fc .getExternalContext().getSession(false); session.invalidate(); return "LoginPage"; } The following code snippet allows to terminate the session from the jsp page: <% session.invalidate(); %>

37.How to reload the page after ValueChangeListener is invoked?

At the end of the ValueChangeListener, call FacesContext.getCurrentInstance().renderResponse();

« Previous | 0 | 1 | 2 | 3 | 4 | Next »


copyright © 2014 - all rights riserved by javatechnologycenter.com