weixin_33736832 2015-01-08 07:18 采纳率: 0%
浏览 97

JSF 1.2 AJAX重定向到URL

I've got a requirement where we need to redirect to a page for JSF 1.2 Ajax call. In our case, we need to redirect to session expired page when the ajax call get fired after the session got expired. We are implementing the session expiry check in a filter and the invocation of httpservletresponse.sendRedirect is redirecting correctly to the session expired page as expected, but the url is not getting changed which is the issue now.

Any hints/soultion either at the client/server side is highly appreciated.

~Ragesh

  • 写回答

1条回答 默认 最新

  • weixin_33691817 2015-01-09 11:40
    关注

    Finally I managed to find a solution for the above problem.

    In the filter, I set the response header "Location" and another custom header which I'll use in the client side to filter the response.

    Filter code:

    httpServletResponse.setStatus(HttpServletResponse.SC_OK);
    httpServletResponse.setHeader("x-timeout-status", "true");
    httpServletResponse.setHeader("Location", httpServletResponse
                                .encodeRedirectURL(sessionexpiryurl));
    

    Richfaces have got a javascript file with various callbacks required during the AJAX call invocation which is packed inside the Richfaces libraries. There is one callback function called "processResponse" which will get invoked upon receiving response for all AJAX call initiated by JSF Ajax components . I've made use of this to handle the redirection functionality.

    JS code:

    var originalAjaxProcessResponse = A4J.AJAX.processResponse;
    
    A4J.AJAX.processResponse = function(req) {
        if (req.getResponseHeader('x-timeout-Status') != undefined && req.getResponseHeader('x-timeout-status') == 'true') {
            window.location.href = req.getResponseHeader('Location');
        } else {
            originalAjaxProcessResponse(req);
        }   
    }
    

    Here we are overriding the method to handle our specific case and delegate the rest of the ajax call response handling to the in-built processing provided by richfaces.

    Please let me know if you see any limitation to this solution or have a better solution to this problem

    ~Ragesh

    评论

报告相同问题?

悬赏问题

  • ¥100 求数学坐标画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站