I currently have the following problem with Apache Tapestry 5.3.1: The user should be able to edit his profile details and to change his password. For the data there is a "User" entity.

I cannot use the getPassword method of user, as passwords are stored encrypted with a salt that always changes (using Apache Tynamo). As a result, I am trying to store the values in two page properties called passwordValue1 and passwordValue2 and use the rest of the bean. On validations both passwordValue fields are null, even if I typed something and then submitted the form. Any ideas why?

        <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>

The java code for the tapestry page:

@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");
    }
}
有帮助吗?

解决方案

Your validation method does not specify what you want to validate. Rename the method to onValidateFromRegisterForm

Explanation: Every field also triggers a validate event, so it gets called for each field. Those validations are triggered right after a field is set. So when the first field is set, the onValidate is called and it checks BOTH fields but of course, all the other fields were not set yet and fail the validation.

This might help: What is called when on the jumpstart page.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top