1

I have a very simple problem but for the life of me I can't see where I'm going wrong. I have started to create a 'reset password' page with email and password inputs and a commandButton. Both input fields are required, but if I leave for example the password empty and click the button no message is displayed, and the server reports a warning:

WARNING: There are some unhandled FacesMessages, this means not every FacesMessage had a chance to be rendered. These unhandled FacesMessages are: - Please enter a new password

This is my page:

<!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>

and my backing bean:

    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);
        }
    }
}

and faces config:

<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>

Could someone please tell me where I'm going wrong?

Thanks, Neil

opalenzuela
  • 3,139
  • 21
  • 41
Neil Richards
  • 131
  • 1
  • 4
  • 16

2 Answers2

1

You need to update the h:messages part after submitting the form, otherwise it is not possible to display any message there. I.e. use the following for the commandButton

<p:commandButton update="resetPasswordForm" value="Send" actionListener="#{passwordResetBean.resetPassword}" />
user1983983
  • 4,793
  • 2
  • 15
  • 24
  • Thought I also had a with an autoUpdate in an included page but it turns out I didn't. The explicit update does work as you suggest, but now I've added the and removed the update parameter, I don't get the growl and still get the warning message. This should now work I reckon but still no joy. Don't really want to use the update parameter if I can help it. – Neil Richards Oct 25 '13 at 14:06
0

PrimeFaces messages can use autoupdate

<p:messages id="messages" globalOnly="true" autoUpdate="true" closable="true"  />
Kuba
  • 2,069
  • 23
  • 30
  • You're right - autoUpdate was a glaring omission. The was an afterthough as I thought I already had a with an autoUpdate in an included file (which I now realise I didn't). However, even after adding autoUpdate I still get the same message :( – Neil Richards Oct 25 '13 at 14:02