Showing posts with label JSF. Show all posts
Showing posts with label JSF. Show all posts

October 7, 2014

ADF_FACES-30108:The view state of the page has expired because of inactivity. Reload the page.

I have several tabs in my portal application, in which some of them are loading data from web services. Some times when I click on those tabs, an alert message with the below error message is displaying and on-click of Ok button, the app is reloading.

The error message:

ADF_FACES-60098:Faces lifecycle receives unhandled exceptions in phase RESTORE_VIEW 1
javax.faces.application.ViewExpiredException: viewId:/oracle/webcenter/portalapp/pages/home.jspx - ADF_FACES-30108:The view state of the page has expired because of inactivity.  Reload the page.

Solution:

To ignore this error, I have written a filter which validates the app session on every navigation.  And my filter would look like,

package portal;

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 MyFilter implements Filter {
    private FilterConfig fc = null;

    public MyFilter() {
        super();
    }

    public void init(FilterConfig filterConfig) throws ServletException {
        fc = filterConfig;
    }

    public void doFilter(ServletRequest servletRequest,
                         ServletResponse servletResponse,
                         FilterChain filterChain) throws IOException,
                                                         ServletException {
        String reqSessionID =
            ((HttpServletRequest)servletRequest).getreqSessionIDId();
        String currentSessionID =
            ((HttpServletRequest)servletRequest).getSession().getId();
        String requestURI =
            ((HttpServletRequest)servletRequest).getRequestURI();
        boolean sameSession =
            currentSessionID.equalsIgnoreCase(reqSessionID);
        System.out.println("currentSessionID == reqSessionID? : " + sameSession);
        if (!sameSession && reqSessionID != null) {
              //((HttpServletResponse)servletResponse).sendRedirect(requestURI);
            System.out.println("Session is null");
        } else {
            filterChain.doFilter(servletRequest, servletResponse);
            System.out.println("Continue to servlet.");
        }
    }

    public void destroy() {
        fc = null;
    }
}

Configured the above filter in web.xml file as below.
<filter>
 <filter-name>AppSessionFilter</filter-name>
   <filter-class>portal.MyFilter</filter-class>
 </filter>
<filter-mapping>
  <filter-name>AppSessionFilter</filter-name>
   <servlet-name>Faces Servlet</servlet-name>
</filter-mapping>

February 25, 2014

Invoking constructor twice in JSFF with panelTabbed component

I have a JSFF page which has panelTabbed component with four tabs and one of the tabs is displaying data from a managed bean. While loading the page, the bean constructor is being called twice. To avoid this add the below property to the panelTabbed tag,  which will avoid loading the tab data until it shows.


childCreation="lazyUncached"

February 24, 2014

Including a JSF page into another JSF page

Like jsp page, we can also include a JSF page into another JSF page by using the same jsp directive jsp:include.

Example:

<jsp:include page="test.jspx" flush="true"></jsp:include>