Logo F2FInterview

JSF Interview Questions

Q   |   QA

You can get it using initParam pre-defined JSF EL valiable. 

For example, if you have:

<context-param> <param-name>productId</param-name> <param-value>2004Q4</param-value></context-param>

You can access this parameter with #{initParam['productId']} .

For example:

Product Id: <h:outputText value=”#{initParam['productId']}”/>

You can get it using externalContext getInitParameter method. For example, if you have:





You can access this connection string with:

FacesContext fc = FacesContext.getCurrentInstance();
String connection = fc.getExternalContext().getInitParameter("connectionString");

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);
return "login_page";

The following code snippet allows to terminate the session from the jsp page:

<% session.invalidate(); %> <c:redirect url=”loginPage.jsf” />

The client-side solution might be very simple. You can wrap the jsp page (or part of it you want to hide) into the DIV, then you can add one more DIV that appears when user clicks the submit button. This DIV can contain the animated gif you speak about or any other content.

Scenario: when user clicks the button, the JavaScript function is called. This function hides the page and shows the “Wait” DIV. You can customize the look-n-fill with CSS if you like.

This is a working example:

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<f:loadBundle basename="demo.bundle.Messages" var="Message"/>
 <title>Input Name Page</title>
 function gowait() {
 <body bgcolor="white">
 <div id="main">
 <h1><h:outputText value="#{Message.inputname_header}"/></h1>
 <h:messages style="color: red"/>
 <h:form id="helloForm">
 <h:outputText value="#{Message.prompt}"/>
 <h:inputText id="userName" value="#{GetNameBean.userName}" required="true">
 <f:validateLength minimum="2" maximum="20"/>
 <h:commandButton onclick="gowait()" id="submit"
 action="#{GetNameBean.action}" value="Say Hello" />
 <div id="wait" style="visibility:hidden; position: absolute; top: 0; left: 0">
 <table width="100%" height ="300px">
 <td align="center" valign="middle">
 <h2>Please, wait...</h2>

If you want to have an animated gif of the “Wait” Page, the gif should be reloaded after the form is just submitted. So, assign the id for your image and then add reload code that will be called after some short delay. For the example above, it might be:

 function gowait() {
 window.setTimeout('showProgress()', 500);
 function showProgress(){
 var wg = document.getElementById("waitgif");
<img id="waitgif" src="animated.gif">

Yes. You can define the list of the configuration files in the web.xml.

This is an example:


Note: Do not register /WEB-INF/faces-config.xml file in the web.xml . Otherwise, the JSF implementation will process it twice.

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: