创建一个调用jsf方法的简单链接 [英] creating a simple link that invokes a jsf method
问题描述
我正在建立注销链接,这是注销bean的代码.
i'm making a logout link and this is the code of the logout bean.
public void doLogout() {
try {
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("user_info", null);
FacesContext.getCurrentInstance().getExternalContext().redirect("../index.xhtml");
} catch (Exception e) {
}
}
在我的xhtml页面中
in my xhtml page i have
<ul class="dropdown-menu">
<li><h:outputLink value="#{logout.doLogout()}">Logout</h:outputLink></li>
</ul>
我的问题是,当我进入该页面时,该页面会自动将我注销,并调用logout.doLogout()方法,而无需我单击链接本身.
my problem is when i get into the page, the page automatically logs me out, its invoking the logout.doLogout() method without me clicking the link itself.
我尝试擦除doLogout()中的代码,并将其更改为一个Sysout,然后调用该方法,而无需单击链接.
i tried erasing the code inside the doLogout() and just change it to simply a Sysout, and it does invoke the method with out me clicking the link.
推荐答案
对我来说太愚蠢了.<h:commandLink action="logout.doLogout()">Logout</h:commandLink>
可以完成工作.
oh stupid of me.. <h:commandLink action="logout.doLogout()">Logout</h:commandLink>
does the job.
这篇关于创建一个调用jsf方法的简单链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!