1

我有一个非常简单的问题,但对于我的生活,我看不出哪里出错了。我已经开始创建一个带有电子邮件和密码输入以及一个命令按钮的“重置密码”页面。两个输入字段都是必需的,但是如果我将密码留空并单击按钮,则不会显示任何消息,并且服务器会报告警告:

警告:有一些未处理的 FacesMessage,这意味着不是每个 FacesMessage 都有机会被渲染。这些未处理的 FacesMessage 是: - 请输入新密码

这是我的页面:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">

    <h:head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
        <link type="text/css" rel="stylesheet" href="/css/main.css" />
        <title>Request Password Reset</title>
    </h:head>

    <h:body>
        <p:outputPanel layout="block" id="container">

            <ui:include src="/header-branding-only.xhtml" />

            <h3>
                Reset Password
            </h3>

            <p:outputPanel id="content" layout="block">

                <p>
                    <h:outputText value="Please enter your email address, a password of 8 characters or more and click 'Reset'." />
                </p>

                <h:form id="resetPasswordForm">

                    <p:panelGrid columns="2" styleClass="invisible-middlealign">

                        <p:panelGrid columns="2" styleClass="formatted" columnClasses="tdasheader, null">

                            <h:outputText value="Email Address" />
                            <p:inputText value="#{passwordResetBean.email}" size="40" 
                                required="true" requiredMessage="Please enter your email address" />

                            <h:outputText value="New Password" />
                            <p:password value="#{passwordResetBean.password}" size="40" 
                                required="true" requiredMessage="Please enter a new password" />

                        </p:panelGrid>

                        <p:commandButton value="Send" actionListener="#{passwordResetBean.resetPassword}" />

                    </p:panelGrid>

                    <h:messages style="color:red" />
                </h:form>

            </p:outputPanel>

            <ui:include src="/footer.xhtml" />

        </p:outputPanel>

    </h:body>

</html>

和我的支持豆:

    public PasswordResetBean() throws ApplicationException {

            uuid = FacesUtil.getRequestParameter("uuid");
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void resetPassword(ActionEvent event) {

        try {
            boolean successful = securityService.resetPassword(email, password, uuid, userId);

            if (successful) {
                FacesUtil.getHttpSession(true).setAttribute("passwordReset", true);
                FacesUtil.redirect(FacesUtil.getServletRequest().getContextPath()+"/logon.xhtml");
            }
            else {
                FacesContext context = FacesContext.getCurrentInstance();
                FacesMessage message = new FacesMessage("The reset has failed. Please try again");
                context.addMessage("resetPasswordForm", message);
            }
        }
        catch (Exception e) {
            handleException(e);
        }
    }
}

并面对配置:

<managed-bean>
    <managed-bean-name>passwordResetBean</managed-bean-name>
    <managed-bean-class>com.encounter.security.ui.PasswordResetBean</managed-bean-class>
    <managed-bean-scope>view</managed-bean-scope>
    <managed-property>
        <property-name>securityService</property-name>
        <value>#{securityService}</value>
    </managed-property>
</managed-bean>

有人可以告诉我哪里出错了吗?

谢谢,尼尔

4

2 回答 2

1

您需要h:messages在提交表单后更新该部分,否则无法在此处显示任何消息。即使用以下命令按钮

<p:commandButton update="resetPasswordForm" value="Send" actionListener="#{passwordResetBean.resetPassword}" />
于 2013-10-25T12:52:51.447 回答
0

PrimeFaces 消息可以使用自动更新

<p:messages id="messages" globalOnly="true" autoUpdate="true" closable="true"  />
于 2013-10-25T13:01:38.650 回答