-1

Primefaces(V6.0.0)

I am trying to logout from Application, but when I click logout menulink, nothing happen.

Following is xhtml code

  <p:submenu label="LogOut">
          <p:menuitem value="LogOut" onclick="selectComponentLink(this)" action="#{loginBean.logout}" url="/login.xhtml" />
</p:submenu>

LoginBean.java

public String logout() {        
          return "login.html";
    }

How do I call logout() method define in LoginBean.java when user click on logout menulink?

Neerajkumar
  • 300
  • 4
  • 19
  • Your last question/bullitpoint is a separate one and should be removed, for your first two see the PrimeFaces showcase. And as you stated the 'URL' part is irrelevant. Totally remove it from your question then. And as requested multiple times now, PLEASE create a [mcve] – Kukeltje Apr 27 '17 at 17:21
  • And 'generalize' your question. 'Logout' and 'sign out' are totally irrelevant. And start by reading and memorizing all JSF questions that have more than 30 upvotes (or start with 50), e.g. http://stackoverflow.com/questions/2118656/commandbutton-commandlink-ajax-action-listener-method-not-invoked-or-input-value/2120183#2120183 – Kukeltje Apr 27 '17 at 17:22
  • @Kukeltje, Sorry for making spam question. I have made changes in question. Hope you are okay with this, – Neerajkumar Apr 28 '17 at 04:26

1 Answers1

0

Just wanted to add answer for this question, If I remove onclick="selectComponentLink(this)" then I can call action="#{loginBean.logout}"

Here is full code,

<p:submenu label="Sign out">
    <p:menuitem value="Sign out"  action="#{loginBean.logout}" immediate="true" />                            
</p:submenu>

loginBean.java

public String logout() {
    FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
             return "/login.html?faces-redirect=true";
        }

Hope this answer is helps others. :)

Neerajkumar
  • 300
  • 4
  • 19