1 2 Previous Next 15 Replies Latest reply on Jan 29, 2009 3:42 AM by ramki dirisala

    session handling in richfaces

    ramki dirisala Novice

      hi,
      i want to handle session timeout exception in our application. how can i redirect user to session timeout page.

        • 2. Re: session handling in richfaces
          ramki dirisala Novice

          hi,
          thanks for reply. i saw that link. but i don't how to implement that in my app. i want to show one logout page when session expires. can you please give some sample code.

          • 3. Re: session handling in richfaces
            Nick Belaevski Master

            Hello,

            Have you tried defining error-page for view expired exception?

            • 4. Re: session handling in richfaces
              ramki dirisala Novice

              hi,
              i have the following configuration in web.xml

              <context-param>

              <param-name>org.ajax4jsf.handleViewExpiredOnClient</param-name>

              <param-value>true</param-value>

              </context-param>

              <error-page>
              <exception-type>
              javax.faces.application.ViewExpiredException
              </exception-type>
              /Pages/errorpage.htm
              </error-page>

              <session-config>
              <session-timeout>1</session-timeout>
              </session-config>

              but when ever i click on any button in my app after session time period. i am getting following error in browser. i am not getting specified error page.

              <?xml version="1.0" encoding="UTF-8" ?>
              -
              -

              <meta name="Ajax-Expired" content="View state could't be restored - reload page ?" />

              • 5. Re: session handling in richfaces
                . . Newbie

                ramki9977,

                You can easily redirect, adding the code below into tag of the main page:

                <meta http-equiv="refresh"
                content="${session.maxInactiveInterval};url=#{facesContext.externalContext.request.scheme}://#{facesContext.externalContext.request.serverName}:#{facesContext.externalContext.request.serverPort}#{facesContext.externalContext.requestContextPath}/errorpage.jsp"
                />


                With this code, when session expiration occurs, user will be automatically redirected to: http://localhost:8080/myapp/errorpage.jsp

                "ramki9977" wrote:
                hi,
                i want to handle session timeout exception in our application. how can i redirect user to session timeout page.


                • 6. Re: session handling in richfaces
                  . . Newbie

                   

                  "rhancke" wrote:
                  ramki9977,

                  You can easily redirect, adding the code below into the head tag of the main page:

                  <meta http-equiv="refresh"
                  content="${session.maxInactiveInterval};url=#{facesContext.externalContext.request.scheme}://#{facesContext.externalContext.request.serverName}:#{facesContext.externalContext.request.serverPort}#{facesContext.externalContext.requestContextPath}/errorpage.jsp"
                  />


                  With this code, when session expiration occurs, user will be automatically redirected to: http://localhost:8080/myapp/errorpage.jsp

                  "ramki9977" wrote:
                  hi,
                  i want to handle session timeout exception in our application. how can i redirect user to session timeout page.


                  • 7. Re: session handling in richfaces
                    ramki dirisala Novice

                    thanks for reply. i will try that one.

                    • 8. Re: session handling in richfaces
                      ramki dirisala Novice

                      hi,
                      i am using facelets for my app. can you please tell me where can i include this code.

                      • 9. Re: session handling in richfaces
                        . . Newbie

                         

                        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                        <html xmlns="http://www.w3.org/1999/xhtml">
                         <head>
                         <meta http-equiv="refresh"
                         content="${session.maxInactiveInterval};url=#{facesContext.externalContext.request.scheme}://#{facesContext.e
                         xternalContext.request.serverName}:#{facesContext.externalContext.request.serverPort}#{facesContext.
                         externalContext.requestContextPath}/errorpage.jsp"
                         />
                         </head>
                         <body>
                         </body>
                        </html>

                        "ramki9977" wrote:
                        hi,
                        i am using facelets for my app. can you please tell me where can i include this code.


                        • 11. Re: session handling in richfaces
                          ramki dirisala Novice

                          hi,
                          i implement what you said. but the problem is, some times sesstion time out page is showing(when session expires). but some times the same page is showing(but in url session timeout page url is showing). can you please help me.

                          • 12. Re: session handling in richfaces
                            Fab Mars Novice

                            Hi
                            May I propose an alternate solution that brings you closer to the good old web.xml way ?

                            Please read: https://javaserverfaces.dev.java.net/issues/show_bug.cgi?id=697

                            ViewExpiredException is a pain because it's encapsulated in a ServletException and therefore you cannot use the standard web.xml mechanism for handling errors.


                            Ok then let's go the hard way: Write your own FacesServlet!

                            package com.company.application.framework;
                            
                            import java.io.IOException;
                            
                            import javax.faces.application.ViewExpiredException;
                            import javax.servlet.Servlet;
                            import javax.servlet.ServletConfig;
                            import javax.servlet.ServletException;
                            import javax.servlet.ServletRequest;
                            import javax.servlet.ServletResponse;
                            
                            public class FacesServlet implements Servlet {
                            
                             private static final long serialVersionUID = 1125125169451561750L;
                            
                             public final static String FACES_SERVLET_PARAM = "facesClass";
                             public final static String FACES_SERVLET_DEFAULT_CLASS = "javax.faces.webapp.FacesServlet";
                            
                             private Servlet delegate;
                            
                             @Override
                             public void init(ServletConfig servletConfig) throws ServletException {
                             String facesClass = servletConfig.getInitParameter(FACES_SERVLET_PARAM);
                             if(facesClass == null) {
                             facesClass = FACES_SERVLET_DEFAULT_CLASS;
                             }
                            
                             try {
                             delegate = (Servlet) Class.forName(facesClass).newInstance();
                             delegate.init(servletConfig);
                             }
                             catch (Exception e) {
                             throw new ServletException(e);
                             }
                             }
                            
                             @Override
                             public String getServletInfo() {
                             return delegate.getServletInfo();
                             }
                            
                             @Override
                             public ServletConfig getServletConfig() {
                             return delegate.getServletConfig();
                             }
                            
                             @Override
                             public void service(ServletRequest req, ServletResponse resp) throws ServletException, IOException, ViewExpiredException {
                             try {
                             delegate.service(req, resp);
                             }
                             catch (ServletException e) {
                             Throwable t = e.getRootCause();
                             if (t instanceof ViewExpiredException) {
                             throw (ViewExpiredException)t;
                             }
                             else {
                             throw e;
                             }
                             }
                             }
                            
                             @Override
                             public void destroy() {
                             delegate.destroy();
                             }
                            }




                            Then configure it in your web.xml:
                            Replace the usual FacesServlet declaration by your own. In the example here it's for JSF-RI. If using MyFaces, just put the good facesClass value.
                            <servlet>
                             <servlet-name>Faces Servlet</servlet-name>
                             <servlet-class>com.company.application.framework.FacesServlet</servlet-class>
                             <init-param>
                             <param-name>facesClass</param-name>
                             <param-value>javax.faces.webapp.FacesServlet</param-value>
                             </init-param>
                             <load-on-startup>1</load-on-startup>
                             </servlet>




                            Then do the good old way in web.xml:
                            <error-page>
                             <exception-type>javax.faces.application.ViewExpiredException</exception-type>
                             <location>/the/page/where/you/want/to/redirect.jsf</location>
                             </error-page>



                            That's it.

                            • 13. Re: session handling in richfaces
                              ramki dirisala Novice

                              hi,
                              thanks for your reply. we mean to say the solution which tried may not be accurate in all cases?. i read that article. but i don't know is it the good way to write our own faces servlet. suggest me which one is better.

                              • 14. Re: session handling in richfaces
                                Nick Belaevski Master

                                 

                                "ramki9977" wrote:
                                hi,
                                i have the following configuration in web.xml

                                <context-param>

                                <param-name>org.ajax4jsf.handleViewExpiredOnClient</param-name>

                                <param-value>true</param-value>

                                </context-param>

                                <error-page>
                                <exception-type>
                                javax.faces.application.ViewExpiredException
                                </exception-type>
                                <location>/Pages/errorpage.htm</location>
                                </error-page>

                                <session-config>
                                <session-timeout>1</session-timeout>
                                </session-config>

                                but when ever i click on any button in my app after session time period. i am getting following error in browser. i am not getting specified error page.

                                <?xml version="1.0" encoding="UTF-8" ?>
                                - <html xmlns="http://www.w3.org/1999/xhtml">
                                - <head>
                                <meta name="Ajax-Response" content="true" />
                                <meta name="Ajax-Expired" content="View state could't be restored - reload page ?" />
                                </head>
                                </html>


                                Looks like the problem described here: https://jira.jboss.org/jira/browse/RF-5456. Let's see what we can do...

                                1 2 Previous Next