Search code examples
ajaxtemplatesjsffaceletsicefaces

How to change the URL and template page after login?


I am working on a JSF and Hibernate web app with ICEfaces. I am using two Facelets templates, one for the login page and one for the rest of the site.

The problem is, when I click on the login button, it goes to the home page, but without changing the URL nor the template. When I enter the right URL, it goes to it and displays the right template.

I know that ICEfaces uses Ajax and partially updates the page, but I want to know how to stop that, I want it to load the entire requested page.


Solution

  • Just send a redirect after login. You can achieve this by appending a faces-redirect=true request parameter to the navigation outcome.

    public String login() {
        // ...
    
        return "home?faces-redirect-true";
    }
    

    Or if you're still using the ancient JSF 1.x with <navigation-case>s in faces-config.xml, then you can achieve the same by adding a <redirect /> to the <navigation-case> in question.

    <naviagation-case>
        <from-outcome>home</from-outcome>
        <to-view-id>/home.jsf</to-view-id>
        <redirect />
    </navigation-case>