@SuppressWarnings("serial")
private void addPassswordFields()
{
// Password
final FieldsetPanel fs = gridBuilder.newFieldset(getString("password"), getString("passwordRepeat"));
final PasswordTextField passwordField = new PasswordTextField(fs.getTextFieldId(), new PropertyModel<String>(this, "password")) {
@Override
protected void onComponentTag(final ComponentTag tag)
{
super.onComponentTag(tag);
if (passwordUser == null) {
tag.put("value", "");
} else if (StringUtils.isEmpty(getConvertedInput()) == false) {
tag.put("value", MAGIC_PASSWORD);
}
}
};
passwordField.setResetPassword(false).setRequired(isNew());
final PasswordTextField passwordRepeatField = new PasswordTextField(fs.getTextFieldId(), new PropertyModel<String>(this,
"passwordRepeat")) {
@Override
protected void onComponentTag(final ComponentTag tag)
{
super.onComponentTag(tag);
if (passwordUser == null) {
tag.put("value", "");
} else if (StringUtils.isEmpty(getConvertedInput()) == false) {
tag.put("value", MAGIC_PASSWORD);
}
}
};
passwordRepeatField.setResetPassword(false).setRequired(false);
passwordRepeatField.add(new AbstractValidator<String>() {
@Override
protected void onValidate(final IValidatable<String> validatable)
{
final String passwordRepeatInput = validatable.getValue();
passwordField.validate();
final String passwordInput = passwordField.getConvertedInput();
if (StringUtils.isEmpty(passwordInput) == true && StringUtils.isEmpty(passwordRepeatInput) == true) {
return;
}
if (StringUtils.equals(passwordInput, passwordRepeatInput) == false) {
passwordUser = null;
validatable.error(new ValidationError().addMessageKey("user.error.passwordAndRepeatDoesNotMatch"));
return;
}
if (MAGIC_PASSWORD.equals(passwordInput) == false || passwordUser == null) {
final String errorMsgKey = ((UserDao) getBaseDao()).checkPasswordQuality(passwordInput);
if (errorMsgKey != null) {
passwordUser = null;
validatable.error(new ValidationError().addMessageKey(errorMsgKey));
} else {
passwordUser = new PFUserDO();
((UserDao) getBaseDao()).createEncryptedPassword(passwordUser, passwordInput);
}
}
}
/**
* @see org.apache.wicket.validation.validator.AbstractValidator#validateOnNullValue()
*/
@Override
public boolean validateOnNullValue()
{
// Should be validated (e. g. if password field is given but password repeat field not).
return true;
}
});
WicketUtils.setPercentSize(passwordField, 50);
WicketUtils.setPercentSize(passwordRepeatField, 50);
fs.add(passwordField);
fs.add(passwordRepeatField);
fs.addHelpIcon(getString(UserDao.MESSAGE_KEY_PASSWORD_QUALITY_CHECK));
}