0

I have a template with the Logout Link of name "Cerrar Sesión"

<div id="top">
    <ui:insert name="top">
        <h:form>
            <h:commandLink value="Cerrar Sesión" action="#{loginBean.cerrarSesion}" />
        </h:form>
    </ui:insert>
</div>

My Bean has the cerrarSesion function:

public void cerrarSesion() throws IOException {
    ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
    ec.invalidateSession();
    ec.redirect("../view/index.xhtml?faces-redirect=true");
}

The Project URL is: http://192.168.1.72:8083/PROJECT/

My problem is if I click on "Cerrar Sesión", the URL changes to http://192.168.1.72:8083/PROJECT/faces/view/inicio.xhtml, the same page where I was (it refreshes).

When I clicked on "Cerrar Sesión" again, the program redirects correctly: http://192.168.1.72:8083/PROJECT/faces/view/index.xhtml

I am using JSF with PrimeFaces, NetBeans, and GlassFish.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I was noticing ec.invalidateSession(); maybe it's possible it doesn't redirect, and breaks. Try removing that line and seeing if anything changes. – XaolingBao May 22 '16 at 21:46
  • Could you also try like the first example by BalusC here: http://stackoverflow.com/questions/11277366/what-is-the-difference-between-redirect-and-navigation-forward-and-when-to-use-w. If still nothing works, do you have nested forms? – Jaqen H'ghar May 23 '16 at 05:57
  • You didn't post the problem in MCVE format, so it's merely guessing to the cause. Perhaps it's this? http://stackoverflow.com/questions/11408130 If not, please post a MCVE. – BalusC May 23 '16 at 07:22
  • Hmm, my jsf wouldn't show the link or anything in the body of a ui:insert. It only would insert the contents of a previous ui:define with name="top". An action must be a method, that returns a String. The value will be the outcome, null means the same page. – Holger May 24 '16 at 12:50

0 Answers0