Search in sources :

Example 6 with ValidationError

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;
}
Also used : Locale(java.util.Locale) DateChooser(org.olat.core.gui.components.form.flexible.elements.DateChooser) ItemValidatorProvider(org.olat.core.gui.components.form.flexible.impl.elements.ItemValidatorProvider) UserManager(org.olat.user.UserManager) ValidationError(org.olat.core.gui.components.form.ValidationError) Date(java.util.Date)

Example 7 with ValidationError

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;
}
Also used : Locale(java.util.Locale) ItemValidatorProvider(org.olat.core.gui.components.form.flexible.impl.elements.ItemValidatorProvider) UserManager(org.olat.user.UserManager) ValidationError(org.olat.core.gui.components.form.ValidationError) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement)

Example 8 with ValidationError

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));
}
Also used : URLPropertyHandler(org.olat.user.propertyhandlers.URLPropertyHandler) ValidationError(org.olat.core.gui.components.form.ValidationError) Test(org.junit.Test)

Example 9 with ValidationError

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));
}
Also used : PhonePropertyHandler(org.olat.user.propertyhandlers.PhonePropertyHandler) ValidationError(org.olat.core.gui.components.form.ValidationError) Test(org.junit.Test)

Example 10 with ValidationError

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);
}
Also used : ValidationError(org.olat.core.gui.components.form.ValidationError) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Aggregations

ValidationError (org.olat.core.gui.components.form.ValidationError)24 Locale (java.util.Locale)14 ItemValidatorProvider (org.olat.core.gui.components.form.flexible.impl.elements.ItemValidatorProvider)10 MalformedURLException (java.net.MalformedURLException)4 URL (java.net.URL)4 VelocityContext (org.apache.velocity.VelocityContext)4 Context (org.apache.velocity.context.Context)4 Test (org.junit.Test)4 TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)4 Translator (org.olat.core.gui.translator.Translator)4 Identity (org.olat.core.id.Identity)4 UserManager (org.olat.user.UserManager)4 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)4 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 UserBulkChangeManager (org.olat.admin.user.bulkChange.UserBulkChangeManager)2 UserBulkChangeStep00 (org.olat.admin.user.bulkChange.UserBulkChangeStep00)2 SecurityGroup (org.olat.basesecurity.SecurityGroup)2 DateChooser (org.olat.core.gui.components.form.flexible.elements.DateChooser)2 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)2