我有一个表单,如果用户忘了密码,用户可以重置密码。 的 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>
这是我的托管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";
}
}
我的问题是当我输入登录名和新密码并提交时。数据库中的密码未更新,因此无法使用新密码登录。
我错过了什么?
答案 0 :(得分:1)
您实际上并未在passwordAccount对象中更新密码。
passwordAccount = accountBusinessLocal.findByLogin(login);
// now update the passwordAccount with the entered password
passwordAccount.setPassword(password);
accountBusinessLocal.UpdateAccount(passwordAccount);