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:

<context-param>

<param-name>connectionString</param-name>

<param-value>jdbc:oracle:thin:scott/tiger@cartman:1521:O901DB</param-value>

</context-param>

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);
session.invalidate();
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"/>
<html>
<head>
 <title>Input Name Page</title>
 <script>
 function gowait() {
 document.getElementById("main").style.visibility="hidden";
 document.getElementById("wait").style.visibility="visible";
 }
 </script>
 </head>
 <body bgcolor="white">
 <f:view>
 <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:inputText>
 <h:commandButton onclick="gowait()" id="submit"
 action="#{GetNameBean.action}" value="Say Hello" />
 </h:form>
 </div>
 <div id="wait" style="visibility:hidden; position: absolute; top: 0; left: 0">
 <table width="100%" height ="300px">
 <tr>
 <td align="center" valign="middle">
 <h2>Please, wait...</h2>
 </td>
 </tr>
 </table>
 </div>
 </f:view>
 </body>
</html>

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:

<script>
 function gowait() {
 document.getElementById("main").style.visibility="hidden";
 document.getElementById("wait").style.visibility="visible";
 window.setTimeout('showProgress()', 500);
 }
 function showProgress(){
 var wg = document.getElementById("waitgif");
 wg.src=wg.src;
 }
</script>
....
....
....
<img id="waitgif" src="animated.gif">

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

This is an example:

<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config-navigation.xml,/WEB-INF/faces-beans.xml</param-value>
</context-param>

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: