Question

I have a form where the user can reset his password if he did forget it. resetForm.xhtml

<h:form id="newCustomerForm"  >
                <fieldset>
                    <legend>Rest Password</legend>
                    <table border="0" >
                        <tbody >   
                              <tr type="text">
                                <td>
                                    <p:outputLabel  value="Account Login :" for="pseudo"/>    
                                </td>
                                <p:spacer height="5px" />
                                <td>
                                    <p:inputText id="pseudo" value="#{accountMB.login}" title="Pseudo" required="true" requiredMessage="The Pseudo field is required.">

                                    </p:inputText>
                                    <p:watermark for="pseudo" value="Login" />  
                                    <p:message for="pseudo"  display="text"/>
                                </td>
                            </tr>
                            <tr type="password">
                                <td>
                                    <p:outputLabel  value="New password :" for="pwd1"/>
                                </td>
                                <p:spacer height="5px" />
                                <td>
                                    <p:password id="pwd1" value="#{accountMB.password}" feedback="true" match="pwd2" label="Password 1" required="true" requiredMessage="The Password field is required."/>  
                                    <p:watermark for="pwd1" value="Password" />  
                                    <p:message for="pwd1"/>
                                </td>

                            </tr>
                            <p:spacer height="5px" /> 
                            <tr type="password">
                                <td>
                                    <p:outputLabel  value="Confirm password :" for="pwd2"/>
                                </td>
                                <p:spacer height="5px" />
                                <td>
                                    <p:password id="pwd2" value="#{accountMB.password}" feedback="true" label="Password 2" required="true" requiredMessage="The confirm password field is required."/>  
                                    <p:watermark for="pwd2" value="Confirm Password" />  
                                    <p:message for="pwd2"/>
                                </td>
                            </tr>                          
                        </tbody>
                    </table>
                    <div type="submit" align="right" style="margin-top: 5px">
                        <p:commandButton style="width: 130px; height: 40px" value="Save" ajax="false" icon="ui-icon-circle-check" styleClass="ui-priority-primary" action="#{accountMB.updateAccount()}"/>             
                    </div>  
                </fieldset>    
            </h:form>  

And here is my managed Bean

@ManagedBean(name = "accountMB")
@SessionScoped
public class AccountManagedBean implements Serializable {

    private static Logger logger = Logger.getLogger(AccountManagedBean.class.getName());
    @Inject
    private AccountBusinessLocal accountBusinessLocal;
    private String login;
    private String password;
    private Account passwordAccount;

    public AccountManagedBean() {
        customer = new Customer();
    }

    @PostConstruct
    public void init() {
        passwordAccount= new Account();
    }
  public String updateAccount() {
        logger.log(Level.SEVERE, "*****Update account***** ");
        passwordAccount = accountBusinessLocal.findByLogin(login);
        accountBusinessLocal.UpdateAccount(passwordAccount);
        logger.log(Level.SEVERE, passwordAccount.toString());
        return "login.jsp";
    }
 }

My problem is when i enter the login and the new password and submit. the password in the database isn't updated so i can't login with the new password.

What am i missing??

Was it helpful?

Solution

You're not actually updating the password in the passwordAccount object.

passwordAccount = accountBusinessLocal.findByLogin(login);

// now update the passwordAccount with the entered password
passwordAccount.setPassword(password);

accountBusinessLocal.UpdateAccount(passwordAccount);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top