【问题标题】:primefaces not refreshing the page when using confirmdialog使用confirmdialog时primefaces不刷新页面
【发布时间】:2015-04-21 15:19:03
【问题描述】:

我想创建一个包含注销链接的菜单。

我使用了这个代码:

<p:menubar>
            <p:menuitem value="Logout" oncomplete="confirmation.show()"/>

            <f:facet name="options">
                <p:inputText style="margin-right:10px" />
                <p:commandButton type="button" value="Logout" icon="ui-icon-extlink" />
            </f:facet>
</p:menubar>

<p:confirmDialog message="Are you sure you want to logout?"
            showEffect="bounce" hideEffect="explode"
            header="Logout" severity="alert"
            widgetVar="confirmation">

            <p:commandButton value="Yes Sure" update="messages"
                oncomplete="confirmation.hide()"
                actionListener="#{authBean.logout}"
                 />
            <p:commandButton value="Not Yet" onclick="confirmation.hide()"
                type="button" />

</p:confirmDialog>

这是我从 authBean 登录和注销的方法:

public String login() {
    try{
    UserService userService = new UserService();
    User currentUser = userService.findUser(username, password);
    System.out.println(currentUser);
    if (currentUser != null) {
        HttpSession session = (HttpSession) FacesContext
                .getCurrentInstance().getExternalContext().getSession(true);
        session.setAttribute("currentUser", currentUser);
        return "index";
    } 
    else return null;
    }
    catch (Exception e) {
        e.printStackTrace();
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, e.toString(), e.toString());
        FacesContext.getCurrentInstance().addMessage(null, message);
        return null;
    }

}

public String logout() {
    HttpSession session = (HttpSession) FacesContext.getCurrentInstance()
            .getExternalContext().getSession(false);
    session.invalidate();
    return "login";
}

这是我的面孔配置:

    <navigation-rule>
    <from-view-id>/*</from-view-id>
    <navigation-case>
        <from-outcome>logout</from-outcome>
        <to-view-id>/welcome.xhtml</to-view-id>
        <redirect />
    </navigation-case>
    </navigation-rule>

我的问题是,当我在确认对话框中按“是”时,页面不会刷新为welcome.xhtml。我必须按下相同的菜单按钮或任何其他按钮,以便页面更新。我希望它在确认对话框中按“是”后更新为 welcome.xhtml。

【问题讨论】:

  • 您将返回 "login" 作为结果。这不匹配。
  • 你得到这个问题的答案了吗?我也有同样的问题。

标签: jsf primefaces


【解决方案1】:

我遇到了同样的问题,经过大量阅读和尝试和错误后,我得出的结论是,如果您调用的方法执行重定向,则在命令按钮中您必须使用 action 而不是 actionListener。

还可以查看这篇关于 h:form 的帖子。

PrimeFaces commandButton in confirmDialog not calling backing bean

祝你好运!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-11
    • 2014-03-16
    • 2016-08-07
    • 2015-10-05
    • 2021-08-15
    相关资源
    最近更新 更多