这是方法
public String changePassword(int id){
FacesContext context = FacesContext.getCurrentInstance();
try{
utx.begin();
Wuser wuser= em.find(Wuser.class, id);
wuser.setPassword(passwordv);
utx.commit();
return "login";
}catch (Exception e) {
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
"Error changing password! ",
"Unexpected error when changing password for your account. Please contact the system Administrator");
context.addMessage(null, message);
Logger.getAnonymousLogger().log(Level.SEVERE,
"Unable to change password ",
e);
return null;
}
}
这是jsf
页面
<f:view>
<h:form id="change">
<h:panelGrid columns="3" border="0">
Username: <h:inputText id="username"
requiredMessage="*"
value="#{usermanager.username}"
required="true"/>
<h:message for="change:username" style="color: red"/>
Old Password: <h:inputSecret id="password"
requiredMessage="*"
value="#{usermanager.password}"
required="true"/>
<h:message for="change:password" style="color: red"/>
New Password (verify): <h:inputSecret id="passwordv"
requiredMessage="*"
value="#{usermanager.passwordv}"
required="true"/>
<h:message for="change:passwordv" style="color: red"/>
Id: <h:inputText id="id"
requiredMessage="*"
value="#{usermanager.id}"
required="true"/>
<h:message for="change:id" style="color: red"/>
</h:panelGrid>
<h:commandButton id="submit"
value="Create"
action="#{usermanager.changePassword(id)}"/>
<h:messages style="color: red" globalOnly="true"/>
</h:form>