我目前在使用 Apache Tapestry 5.3.1 时遇到以下问题: 用户应该能够编辑他的个人资料详细信息并更改他的密码。 对于数据,有一个“用户”实体。
我不能使用用户的 getPassword 方法,因为密码是用总是变化的盐加密存储的(使用 Apache Tynamo)。因此,我试图将这些值存储在两个名为 passwordValue1 和 passwordValue2 的页面属性中,并使用该 bean 的其余部分。 在验证时,两个 passwordValue 字段都是空的,即使我输入了一些内容然后提交了表单。 有什么想法吗?
<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>
Tapestry 页面的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");
}
}
最佳答案
您的验证方法没有指定您要验证的内容。 将方法重命名为 onValidateFromRegisterForm
解释: 每个字段还会触发一个验证事件,因此会为每个字段调用它。这些验证在设置字段后立即触发。 因此,当设置第一个字段时,将调用 onValidate 并检查两个字段,但当然,所有其他字段尚未设置且验证失败。
这可能有帮助:What is called when在 Jumpstart 页面上。
关于java - Tapestry 5 : Value of password field not bound to variable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10575817/