我目前在使用 Apache Tapestry 5.3.1 时遇到以下问题:用户应该能够编辑他的个人资料详细信息并更改他的密码。对于数据,有一个“用户”实体。
我不能使用用户的 getPassword 方法,因为密码是用总是变化的盐加密存储的(使用 Apache Tynamo)。因此,我试图将值存储在两个名为 passwordValue1 和 passwordValue2 的页面属性中,并使用 bean 的其余部分。在验证时,两个密码值字段都为空,即使我输入了一些内容然后提交了表单。任何想法为什么?
<t:beaneditform object="currentUserInfo" add="password1,password2" t:id="registerForm"
exclude="username,password,accountLocked,credentialsExpired">
<p:password1>
<t:label for="password1" >Passwort</t:label>
<t:passwordfield t:id="password1" value="passwordValue1" validate="password"/>
</p:password1>
<p:password2>
<t:label for="password2" >Passwort wiederholen</t:label>
<t:passwordfield t:id="password2" value="passwordValue2" validate="password"/>
</p:password2>
</t:beaneditform>
挂毯页面的java代码:
@RequiresUser
public class UserDetails {
@InjectPage
private Index index;
@Inject
UserUtility userUtil;
@Inject
private Session session;
@Inject
@Property
@SessionState(create = false)
private User currentUserInfo; //value is set
@Component(id="password1")
private PasswordField password1;
@Component(id="password2")
private PasswordField password2;
@Property
private String passwordValue2;
@Property
private String passwordValue1;
@InjectComponent
private BeanEditForm registerForm;
//...snip....
void onValidate() {
System.out.println("onvalidate");
if (registerForm.getHasErrors()) {
return;
}
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// both passwordValue1 and passwordValue 2 are null here
if ((passwordValue1 == null && !("".equals(passwordValue1))
|| !passwordValue1.equals(passwordValue2))) {
registerForm.recordError(password1, "Passwords must match");
registerForm.recordError(password2, "Passwords must match");
}
}