Refer below blog to customize 'Session Time out' popup message.
http://www.ateam-oracle.com/customizing-session-time-out-pop-ups/
This blog explains about learning/findings/experiences & Interesting features of Oracle Application Development Framework(ADF) , part of Oracle Fusion Middleware Technologies.
package com.atd.tirepro.view.filter;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseId;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import oracle.adf.controller.v2.lifecycle.Lifecycle;
import oracle.adf.controller.v2.lifecycle.PagePhaseEvent;
import oracle.adf.controller.v2.lifecycle.PagePhaseListener;
import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;
import org.apache.myfaces.trinidad.util.Service;
public class TimeOutListener implements PagePhaseListener {
@SuppressWarnings("compatibility:-1406793285197613021")
private static final long serialVersionUID = 1L;
public TimeOutListener() {
super();
}
/**
* This method determines whether session timed out or not,
* If session timed out , redirects to corresponding Apps Login page
* based on configured properties file
* @param phaseEvent
*/
public void beforePhase(PagePhaseEvent phaseEvent) {
}
public void afterPhase(PagePhaseEvent pagePhaseEvent) {
if (pagePhaseEvent.getPhaseId() == Lifecycle.PREPARE_RENDER_ID) {
FacesContext facesCtx = FacesContext.getCurrentInstance();
ExternalContext extCtx = facesCtx.getExternalContext();
// Get HttpSession instance
HttpSession session = (HttpSession)extCtx.getSession(false);
// Get HttpServletRequest instance
HttpServletRequest req =
(HttpServletRequest)extCtx.getRequest();
if (session != null) {
int secsTimeout = session.getMaxInactiveInterval();
if (secsTimeout > 0) {
String appURL ="http://www.google.com";
secsTimeout += 2;
String jsCall =
"document.acmeStartClientSessionTimers = function()\n" +
"{\n" +
" if(document.acmeSessionTimeoutTimer != null)\n" +
" window.clearTimeout(document.acmeSessionTimeoutTimer);\n" +
"\n" +
" document.acmeSessionTimeoutTimer = window.setTimeout(\"document.acmeClientSessionTimeout();\", " +
secsTimeout * 1000 + ");\n" +
"\n" +
"}\n" +
"document.acmeStartClientSessionTimers();\n" +
"\n" +
"document.acmeClientSessionTimeout = function()\n" +
"{\n" +
" window.location.href = '" + appURL + "' \n" +
"}";
ExtendedRenderKitService rks =
Service.getRenderKitService(facesCtx,
ExtendedRenderKitService.class);
rks.addScript(facesCtx, jsCall);
}
}
}
}
public PhaseId getPhaseId() {
return PhaseId.RESTORE_VIEW;
}
}
adf-settings.xml
file holds project- and library-level settings such as ADF Faces help providers. The configuration settings for the adf-settings.xml
files are fixed and cannot be changed during and after application deployment. There can be multiple adf-settings.xml
files in an application. ADF settings file users are responsible for merging the contents of their configurations.
package com.atd.tirepro.view.filter;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseId;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import oracle.adf.controller.v2.lifecycle.Lifecycle;
import oracle.adf.controller.v2.lifecycle.PagePhaseEvent;
import oracle.adf.controller.v2.lifecycle.PagePhaseListener;
import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;
import org.apache.myfaces.trinidad.util.Service;
public class TimeOutListener implements PagePhaseListener {
@SuppressWarnings("compatibility:-1406793285197613021")
private static final long serialVersionUID = 1L;
public TimeOutListener() {
super();
}
/**
* This method determines whether session timed out or not,
* If session timed out , redirects to corresponding Apps Login page
* based on configured properties file
* @param phaseEvent
*/
public void beforePhase(PagePhaseEvent phaseEvent) {
}
public void afterPhase(PagePhaseEvent pagePhaseEvent) {
if (pagePhaseEvent.getPhaseId() == Lifecycle.PREPARE_RENDER_ID) {
FacesContext facesCtx = FacesContext.getCurrentInstance();
ExternalContext extCtx = facesCtx.getExternalContext();
// Get HttpSession instance
HttpSession session = (HttpSession)extCtx.getSession(false);
// Get HttpServletRequest instance
HttpServletRequest req =
(HttpServletRequest)extCtx.getRequest();
}
}
public PhaseId getPhaseId() {
return PhaseId.RESTORE_VIEW;
}
}
package com.fm.recruitment.view.filter;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class SessionExpiryFilter implements Filter {
private FilterConfig _filterConfig = null;
public SessionExpiryFilter() {
super();
}
public void init(FilterConfig filterConfig) throws ServletException {
_filterConfig = filterConfig;
}
public void doFilter(ServletRequest servletRequest,
ServletResponse servletResponse,
FilterChain filterChain) throws IOException,
ServletException {
String requestedSession =
((HttpServletRequest)servletRequest).getRequestedSessionId();
String currentWebSession =
((HttpServletRequest)servletRequest).getSession().getId();
String requestURI =
((HttpServletRequest)servletRequest).getRequestURI();
boolean sessionOk =
currentWebSession.equalsIgnoreCase(requestedSession);
System.out.println("currentWebSession == requestedSession? : " + sessionOk);
if (!sessionOk && requestedSession != null) {
requestURI="http://www.google.com";
((HttpServletResponse)servletResponse).sendRedirect(requestURI);
System.out.println("redirecting to : " + requestURI);
} else {
filterChain.doFilter(servletRequest, servletResponse);
System.out.println("session is OK");
}
}
public void destroy() {
_filterConfig = null;
}
}
import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.el.MethodExpression;
import javax.el.ValueExpression;
import javax.faces.context.FacesContext;
import oracle.jbo.Row;
import org.apache.myfaces.trinidad.event.SelectionEvent;
/**
* Programmatic invocation of a method that an EL evaluates to.
*
* @param el EL of the method to invoke
* @param paramTypes Array of Class defining the types of the parameters
* @param params Array of Object defining the values of the parametrs
* @return Object that the method returns
*/
private Object invokeEL(String el, Class[] paramTypes, Object[] params) {
FacesContext facesContext = FacesContext.getCurrentInstance();
ELContext elContext = facesContext.getELContext();
ExpressionFactory expressionFactory = facesContext.getApplication().getExpressionFactory();
MethodExpression exp = expressionFactory.createMethodExpression(elContext, el, Object.class, paramTypes);
return exp.invoke(elContext, params);
}
public Object evaluateEL(String el) {
FacesContext facesContext = FacesContext.getCurrentInstance();
ELContext elContext = facesContext.getELContext();
ExpressionFactory expressionFactory = facesContext.getApplication().getExpressionFactory();
ValueExpression exp = expressionFactory.createValueExpression(elContext, el, Object.class);
return exp.getValue(elContext);
}
/**
* This method invoke whenever any row selected in component
* @param selectionEvent
*/
public void empSelListener(SelectionEvent selectionEvent) {
// Below is the code to make the selected row as current row
invokeEL("#{bindings.EmployeesView1.collectionModel.makeCurrent}", new Class[] { SelectionEvent.class }, new Object[] {
selectionEvent });
Row selectedRow = (Row)evaluateEL("#{bindings.EmployeesView1.currentRow}");
System.out.println(selectedRow.getAttribute("LastName"));
}