5 Replies Latest reply on Jul 17, 2011 3:30 AM by Vishwanath Bannur

    How to restore the FacesContext

    Vishwanath Bannur Newbie

      Hi All,

       

      I ahve developed JSF application with richfaces. From the JSF application we are calling the payment gate way application.(Application developed in another technology). After succesfull payement, it will return a controll to our one of the servlet (MyServlet) and the previous faces context will lost.

       

      I need to get the previous faces context in MyServlet.

       

      Please any help can I get to restore the previous faces context object, So that after paymet I can use old faces context?

        • 1. Re: How to restore the FacesContext
          Vishwanath Bannur Newbie

          Any help or any suggestions please?

          • 2. Re: How to restore the FacesContext
            Tommy Bø Newbie

            I believe these are seperate requests, so you should not try to restore the facescontext. Rather use a ViewScoped bean or store information in the session. Also if the payment-application verifies the payment with a callback (not clientside redirect) this would be in another session, so you have to pull this verification from your database or an applicationwide context.

            • 3. Re: How to restore the FacesContext
              Vishwanath Bannur Newbie

              Hi Tommy,

              In my application the logged in user details keeping in a session as below.

               

              FacesUtils.getCurrentSession().setAttribute("UserBean", userbean);

               

              Class FacesUtils(){

               

              public static HttpSession getCurrentSession() {

              return (HttpSession) getFacesContext().getExternalContext().getSession(false);

              }

               

              public static HttpServletRequest getRequestObject(){

              return (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();

              }

               

              public static HttpServletResponse getResponseObject() {

              return (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();

              }

              }

               

              And one of the JSF backing bean calling the JSP (paymentportal.jsp) as code given below .Intern this JSP calls the payementGateway application (Which is developed in another technologies).

              The payment gatewya application URL is: https://demo-ipg-test/Payment/PaymentPortal.aspx?layout=CONBEISDF

               

              HttpServletResponse response = FacesUtils.getResponseObject();

              response.sendRedirect(response.encodeRedirectURL("./../../jsp/paymentportal.jsp"));

               

              After success full payment, control redirects to one of the servlet defined in my application.

              I need the ‘userbean’ from the session in this servlet. How could I access the ‘userbean’ stored in the session?

              Can you please help me or can you give me any suggestion how can I handle this issue?


              • 4. Re: How to restore the FacesContext
                Nick Belaevski Master

                Hi,

                 

                You should be able to take this object using HttpSession#getAttribute - this doesn't require JSF at all. Check Servlet spec for more information.

                • 5. Re: How to restore the FacesContext
                  Vishwanath Bannur Newbie

                  Hi Nick,

                   

                  You are absolutely right. I already tried by getting HttpSession#getAttribute, but I got null value.

                  Because I am setting session using

                   

                  FacesUtils.getCurrentSession().setAttribute("UserBean", userbean);


                  public static HttpSession getCurrentSession() {

                  return (HttpSession) getFacesContext().getExternalContext().getSession(false);

                  }