JSF/Primefaces span onClick自动调用支持Bean

JSF/Primefaces span onClick自动调用支持Bean,jsf,primefaces,Jsf,Primefaces,我正在用JSF做一个项目,遇到了以下问题 当我创建以下跨度时: <ui:composition> <div id="header" class="header"> <p style="float: right; padding-right: 20px"> Welcome, #{infoGet.username} <span class="glyphicon glyphicon-off" style="col

我正在用JSF做一个项目,遇到了以下问题

当我创建以下跨度时:

<ui:composition>
    <div id="header" class="header">
        <p style="float: right; padding-right: 20px">
            Welcome, #{infoGet.username} <span class="glyphicon glyphicon-off" style="color: darkred; cursor: pointer;" onclick="#{Login.logout()}" />
        </p>
    </div>
</ui:composition>
但是,在页面加载时,跨度内的onClick会自动调用,如果我这样做:

public void logout() {
    FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
}
并刷新页面,会话将无效

有没有一种方法可以从span调用方法“onClick”?我需要它是一个标签,这样我就可以正确地使用引导图标元素。我知道onClick通常用于Javascript,但它与JSF一起使用似乎是合乎逻辑的

通过@luiggi mendoza的解决方案进行编辑

将组成更改为:

<ui:composition>
    <div id="header" class="header">
        <h:form style="float: right; padding-right: 20px">
            <h:commandLink action="#{Login.logout()}" styleClass="clearCommand">
                <span class="glyphicon glyphicon-off" style="color: darkred; cursor: pointer;" />
            </h:commandLink>
        </h:form>
        <p style="float: right; padding-right: 20px">
            Welcome, #{infoGet.username}
        </p>
    </div>
</ui:composition>

保持登录状态,现在一切正常

不应将任何表达式语言直接调用到非JSF组件中。您要找的是

<h:form>
    <h:commandLink action="#{Login.logout()}" styleClass="foo">
        <span style="...">logout</span>
    </h:commandLink>
</h:form>

注销
其中
foo
是一个CSS类,您可以在其中清除
的默认格式。然后,您可以使用通用HTML
组件将所需的CSS应用于注销文本

#clearCommand {
    cursor: pointer;
}
<h:form>
    <h:commandLink action="#{Login.logout()}" styleClass="foo">
        <span style="...">logout</span>
    </h:commandLink>
</h:form>