Search code examples
jsf-2richfaces

JSF2 redirect issue


I have login page and dashboard page.

As soon as login process done dashboard page (using navigation rule) will be displayed.

  <navigation-rule>
        <from-view-id>/login.xhtml</from-view-id>
        <navigation-case>
            <from-outcome>dashboard</from-outcome>
            <to-view-id>/viewp/dashboard.xhtml</to-view-id>
        </navigation-case>
    </navigation-rule>

I have filter mapping for all requests.

Here is my scenario, There is client side poller on my dashboard page. When server restarts, poller sends request which will be interpreted by Filter.

Inside Filter I have logic like

If(url.contains("login.xhtml))
{
//dofilter
}else
{
// redirect to login.
}

but somehow this is not redirecting.

One observation I have is, after login even though I am on dashboard page, my URL still is like mydomain/login.xhtml. I think because URL in browser is mydomain/login.xhtml, response.redirect("mydomain/login.xhtml") is not working. Any suggestions?

Thank you,


Solution

  • The poller is executed by JavaScript/Ajax, right? Well, you've got to check in JavaScript/Ajax if the server returned a 302 instead of 200 and handle accordingly. The browser itself doesn't do that automatically for returned JavaScript/Ajax responses, but only for responses on synchronous requests.

    You can use window.location in JavaScript to perform a "redirect". E.g.

    if (ajaxResponseStatus == 302) {
        window.location = newURL;
    }