use of org.olat.core.gui.components.form.ValidationError in project OpenOLAT by OpenOLAT.
the class DatePropertyHandler method addFormItem.
/**
* @see org.olat.user.propertyhandlers.UserPropertyHandler#addFormItem(java.util.Locale, org.olat.core.id.User, java.lang.String, boolean, org.olat.core.gui.components.form.flexible.FormItemContainer)
*/
@Override
public FormItem addFormItem(Locale locale, final User user, String usageIdentifyer, boolean isAdministrativeUser, FormItemContainer formItemContainer) {
org.olat.core.gui.components.form.flexible.elements.DateChooser dateElem = null;
Date val = decode(getInternalValue(user));
dateElem = FormUIFactory.getInstance().addDateChooser(getName(), i18nFormElementLabelKey(), val, formItemContainer);
dateElem.setItemValidatorProvider(new ItemValidatorProvider() {
@Override
public boolean isValidValue(String value, ValidationError validationError, Locale llocale) {
return DatePropertyHandler.this.isValidValue(user, value, validationError, llocale);
}
});
UserManager um = UserManager.getInstance();
if (um.isUserViewReadOnly(usageIdentifyer, this) && !isAdministrativeUser) {
dateElem.setEnabled(false);
}
if (um.isMandatoryUserProperty(usageIdentifyer, this)) {
dateElem.setMandatory(true);
}
dateElem.setExampleKey("form.example.free", new String[] { Formatter.getInstance(locale).formatDate(new Date()) });
return dateElem;
}
use of org.olat.core.gui.components.form.ValidationError in project OpenOLAT by OpenOLAT.
the class Generic127CharTextPropertyHandler method addFormItem.
/**
* @see org.olat.user.propertyhandlers.UserPropertyHandler#addFormItem(java.util.Locale, org.olat.core.id.User, java.lang.String, boolean, org.olat.core.gui.components.form.flexible.FormItemContainer)
*/
@Override
public FormItem addFormItem(Locale locale, final User user, String usageIdentifyer, boolean isAdministrativeUser, FormItemContainer formItemContainer) {
org.olat.core.gui.components.form.flexible.elements.TextElement tElem = null;
tElem = FormUIFactory.getInstance().addTextElement(getName(), i18nFormElementLabelKey(), 127, getInternalValue(user), formItemContainer);
tElem.setItemValidatorProvider(new ItemValidatorProvider() {
@Override
public boolean isValidValue(String value, ValidationError validationError, Locale llocale) {
return Generic127CharTextPropertyHandler.this.isValidValue(user, value, validationError, llocale);
}
});
tElem.setLabel(i18nFormElementLabelKey(), null);
UserManager um = UserManager.getInstance();
if (um.isUserViewReadOnly(usageIdentifyer, this) && !isAdministrativeUser) {
tElem.setEnabled(false);
}
if (um.isMandatoryUserProperty(usageIdentifyer, this)) {
tElem.setMandatory(true);
}
return tElem;
}
use of org.olat.core.gui.components.form.ValidationError in project openolat by klemens.
the class UserPropertiesTest method testURLPropertyHandlerValidation.
@Test
public void testURLPropertyHandlerValidation() {
URLPropertyHandler urlHandler = new URLPropertyHandler();
ValidationError error = new ValidationError();
// test for valid URL's
assertTrue(urlHandler.isValidValue(null, "http://www.openolat.org", error, null));
assertTrue(urlHandler.isValidValue(null, "https://www.openolat.org", error, null));
assertTrue(urlHandler.isValidValue(null, "http://test.ch", error, null));
assertTrue(urlHandler.isValidValue(null, "http://localhost", error, null));
// test for invalid URL's
assertFalse(urlHandler.isValidValue(null, "http:www.openolat.org", error, null));
assertFalse(urlHandler.isValidValue(null, "www.openolat.org", error, null));
}
use of org.olat.core.gui.components.form.ValidationError in project openolat by klemens.
the class UserPropertiesTest method testPhonePropertyHandlerValidation.
@Test
public void testPhonePropertyHandlerValidation() {
PhonePropertyHandler phoneHandler = new PhonePropertyHandler();
ValidationError error = new ValidationError();
// test for valid phone number formats
assertTrue(phoneHandler.isValidValue(null, "043 544 90 00", error, null));
assertTrue(phoneHandler.isValidValue(null, "043/544'90'00", error, null));
assertTrue(phoneHandler.isValidValue(null, "043/544'90'00", error, null));
assertTrue(phoneHandler.isValidValue(null, "043-544-90-00", error, null));
assertTrue(phoneHandler.isValidValue(null, "043.544.90.00", error, null));
assertTrue(phoneHandler.isValidValue(null, "+41 43 544 90 00", error, null));
assertTrue(phoneHandler.isValidValue(null, "+41 (0)43 544 90 00", error, null));
assertTrue(phoneHandler.isValidValue(null, "+41 43 544 90 00 x0", error, null));
assertTrue(phoneHandler.isValidValue(null, "+41 43 544 90 00 ext. 0", error, null));
assertTrue(phoneHandler.isValidValue(null, "+41 43 544 90 00 ext0", error, null));
assertTrue(phoneHandler.isValidValue(null, "+41 43 544 90 00 ext 0", error, null));
assertTrue(phoneHandler.isValidValue(null, "+41 43 544 90 00 extension 0", error, null));
assertTrue(phoneHandler.isValidValue(null, "+41 43 544 90 00 Extension 0", error, null));
// test for invalid phone number formats
assertFalse(phoneHandler.isValidValue(null, "+41 43 frentix GmbH", error, null));
}
use of org.olat.core.gui.components.form.ValidationError in project openolat by klemens.
the class RegistrationAdminController method validateFormLogic.
@Override
protected boolean validateFormLogic(UserRequest ureq) {
boolean allOk = true;
String whiteList = domainListElement.getValue();
domainListElement.clearError();
if (StringHelper.containsNonWhitespace(whiteList)) {
List<String> normalizedList = registrationModule.getDomainList(whiteList);
List<String> errors = registrationManager.validateWhiteList(normalizedList);
if (!errors.isEmpty()) {
StringBuilder sb = new StringBuilder();
for (String error : errors) {
if (sb.length() > 0)
sb.append(" ,");
sb.append(error);
}
domainListElement.setErrorKey("admin.registration.domains.error", new String[] { sb.toString() });
allOk &= false;
}
}
if (staticPropElement.isSelected(0)) {
if (propertyElement.isOneSelected()) {
String propertyName = propertyElement.getSelectedKey();
String value = propertyValueElement.getValue();
UserPropertyHandler handler = userPropertiesConfig.getPropertyHandler(propertyName);
if (handler != null) {
ValidationError validationError = new ValidationError();
boolean valid = handler.isValidValue(null, value, validationError, getLocale());
if (!valid) {
propertyValueElement.setErrorKey("admin.registration.propertyValue.error", null);
allOk &= false;
}
}
}
}
return allOk && super.validateFormLogic(ureq);
}
Aggregations