use of org.olat.core.gui.components.form.ValidationError in project OpenOLAT by OpenOLAT.
the class URLPropertyHandler method isValid.
@Override
public boolean isValid(User user, FormItem formItem, Map<String, String> formContext) {
// check parent rules first: check if mandatory and empty
if (!super.isValid(user, formItem, formContext))
return false;
org.olat.core.gui.components.form.flexible.elements.TextElement uiEl = (org.olat.core.gui.components.form.flexible.elements.TextElement) formItem;
String value = uiEl.getValue();
ValidationError validationError = new ValidationError();
boolean valid = isValidValue(user, value, validationError, formItem.getTranslator().getLocale());
if (!valid) {
uiEl.setErrorKey(validationError.getErrorKey(), new String[] {});
}
return valid;
}
use of org.olat.core.gui.components.form.ValidationError in project OpenOLAT by OpenOLAT.
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);
}
use of org.olat.core.gui.components.form.ValidationError in project OpenOLAT by OpenOLAT.
the class UserWebService method validateProperty.
private boolean validateProperty(User user, String value, UserPropertyHandler userPropertyHandler, List<ErrorVO> errors, UserManager um, Locale locale) {
ValidationError error = new ValidationError();
if (!StringHelper.containsNonWhitespace(value) && um.isMandatoryUserProperty(PROPERTY_HANDLER_IDENTIFIER, userPropertyHandler)) {
Translator translator = new PackageTranslator("org.olat.core", locale);
String translation = translator.translate("new.form.mandatory");
errors.add(new ErrorVO("org.olat.core:new.form.mandatory:" + userPropertyHandler.getName(), translation));
return false;
}
value = parseUserProperty(value, userPropertyHandler, locale);
if (!userPropertyHandler.isValidValue(user, value, error, locale)) {
String pack = userPropertyHandler.getClass().getPackage().getName();
Translator translator = new PackageTranslator(pack, locale);
String translation = translator.translate(error.getErrorKey(), error.getArgs());
errors.add(new ErrorVO(pack, error.getErrorKey(), translation));
return false;
} else if ((userPropertyHandler.getName().equals(UserConstants.INSTITUTIONALEMAIL) && StringHelper.containsNonWhitespace(value)) || userPropertyHandler.getName().equals(UserConstants.EMAIL)) {
if (!UserManager.getInstance().isEmailAllowed(value, user)) {
String pack = userPropertyHandler.getClass().getPackage().getName();
Translator translator = new PackageTranslator(pack, locale);
String translation = translator.translate("form.name." + userPropertyHandler.getName() + ".error.exists", new String[] { value });
translation += " (" + value + ")";
errors.add(new ErrorVO("org.olat.user.propertyhandlers:new.form.name." + userPropertyHandler.getName() + ".exists", translation));
}
}
return true;
}
use of org.olat.core.gui.components.form.ValidationError in project OpenOLAT by OpenOLAT.
the class LLEditForm method addNewFormLink.
/**
* Add a new form link line to the list of link elements.
*
* @param link the link model object
*/
private void addNewFormLink(int index, final LLModel link) {
// add link target
TextElement lTarget = uifactory.addTextElement("target" + counter, null, -1, link.getTarget(), flc);
lTarget.setPlaceholderKey("target.example", null);
lTarget.clearError();
lTarget.setEnabled(!link.isIntern());
lTarget.setDisplaySize(40);
lTarget.setMandatory(true);
lTarget.setNotEmptyCheck("ll.table.target.error");
lTarget.setItemValidatorProvider(new ItemValidatorProvider() {
public boolean isValidValue(String value, ValidationError validationError, Locale locale) {
try {
if (!value.contains("://")) {
value = "http://".concat(value);
}
new URL(value);
} catch (MalformedURLException e) {
validationError.setErrorKey("ll.table.target.error.format");
return false;
}
return true;
}
});
lTarget.addActionListener(FormEvent.ONCHANGE);
lTarget.setUserObject(link);
lTargetInputList.add(index, lTarget);
// add html target
SingleSelection htmlTargetSelection = uifactory.addDropdownSingleselect("html_target" + counter, flc, new String[] { BLANK_KEY, SELF_KEY }, new String[] { translate("ll.table.html_target"), translate("ll.table.html_target.self") }, null);
htmlTargetSelection.setUserObject(link);
htmlTargetSelection.select((SELF_KEY.equals(link.getHtmlTarget()) ? SELF_KEY : BLANK_KEY), true);
lHtmlTargetInputList.add(index, htmlTargetSelection);
// add link description
TextElement lDescription = uifactory.addTextElement("description" + counter, null, -1, link.getDescription(), flc);
lDescription.clearError();
lDescription.setDisplaySize(20);
lDescription.setNotEmptyCheck("ll.table.description.error");
lDescription.setMandatory(true);
lDescription.setPlaceholderKey("ll.table.description", null);
lDescription.setUserObject(link);
lDescriptionInputList.add(index, lDescription);
// add link comment
TextElement lComment = uifactory.addTextAreaElement("comment" + counter, null, -1, 2, 50, true, link.getComment(), flc);
lComment.setPlaceholderKey("ll.table.comment", null);
lComment.setDisplaySize(20);
lComment.setUserObject(link);
lCommentInputList.add(index, lComment);
// add link add action button
FormLink addButton = new FormLinkImpl("add" + counter, "add" + counter, "", Link.BUTTON_SMALL + Link.NONTRANSLATED);
addButton.setUserObject(link);
addButton.setDomReplacementWrapperRequired(false);
addButton.setIconLeftCSS("o_icon o_icon-lg o_icon-fw o_icon_add");
flc.add(addButton);
lAddButtonList.add(index, addButton);
// add link deletion action button
FormLink delButton = new FormLinkImpl("delete" + counter, "delete" + counter, "", Link.BUTTON_SMALL + Link.NONTRANSLATED);
delButton.setUserObject(link);
delButton.setDomReplacementWrapperRequired(false);
delButton.setIconLeftCSS("o_icon o_icon-lg o_icon-fw o_icon_delete_item");
flc.add(delButton);
lDelButtonList.add(index, delButton);
// custom media action button
FormLink mediaButton = new FormLinkImpl("media" + counter, "media" + counter, " ", Link.NONTRANSLATED);
mediaButton.setIconLeftCSS("o_icon o_icon_browse o_icon-lg");
mediaButton.setDomReplacementWrapperRequired(false);
mediaButton.setUserObject(link);
flc.add(mediaButton);
lCustomMediaButtonList.add(index, mediaButton);
// increase the counter to enable unique component names
counter++;
}
use of org.olat.core.gui.components.form.ValidationError in project OpenOLAT by OpenOLAT.
the class AbstractTextElement method checkItemValidatorIsValid.
private boolean checkItemValidatorIsValid() {
Locale locale = getTranslator().getLocale();
ValidationError validationErrorCallback = new ValidationError();
boolean isValid = itemValidatorProvider.isValidValue(value, validationErrorCallback, locale);
if (isValid) {
return true;
}
setErrorKey(validationErrorCallback.getErrorKey(), validationErrorCallback.getArgs());
return false;
}
Aggregations