Logo F2FInterview

JSF Interview Questions

Q   |   QA

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. <%@ tagliburi=”http://java.sun.com/jsf/core “ prefix=”f” %> (For Core Tags) <%@ tagliburi=”http://java.sun.com/jsf/html “ prefix=”h” %> (For Html Tags)

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

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.

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:

<h:outputLink value=”#{facesContext.externalContext.requestContextPath}/myPage.faces”>

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)

In order to link this F2FInterview's page as Reference on your website or Blog, click on below text area and pres (CTRL-C) to copy the code in clipboard or right click then copy the following lines after that paste into your website or Blog.

Get Reference Link To This Page: (copy below code by (CTRL-C) and paste into your website or Blog)
HTML Rendering of above code: