use of org.olat.core.gui.components.form.ValidationError in project openolat by klemens.
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 klemens.
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 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 klemens.
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 klemens.
the class LinksPortletEditController method initForm.
/**
* @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#initForm(org.olat.core.gui.components.form.flexible.FormItemContainer, org.olat.core.gui.control.Controller, org.olat.core.gui.UserRequest)
*/
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
title = uifactory.addTextElement("link.title", "link.title", 200, portletLink.getTitle(), formLayout);
title.setMandatory(true);
title.setNotEmptyCheck("link.title.not.empty");
desc = uifactory.addRichTextElementForStringDataMinimalistic("link.desc", "link.desc", portletLink.getDescription(), 5, -1, formLayout, getWindowControl());
linkURL = uifactory.addTextElement("link.url", "link.url", 1024, portletLink.getUrl(), formLayout);
linkURL.setMandatory(true);
linkURL.setNotEmptyCheck("link.url.not.empty");
linkURL.setItemValidatorProvider(new ItemValidatorProvider() {
@Override
public boolean isValidValue(String value, final ValidationError validationError, final Locale locale) {
try {
if (!value.contains("://")) {
value = "http://".concat(value);
}
new URL(value);
} catch (final MalformedURLException e) {
validationError.setErrorKey("link.url.not.empty");
return false;
}
return true;
}
});
openPopup = uifactory.addCheckboxesHorizontal("link.open.new.window", "link.open.new.window", formLayout, new String[] { TARGET_BLANK }, new String[] { "" });
if (portletLink.getTarget().equals(TARGET_BLANK)) {
openPopup.selectAll();
}
// language
Map<String, String> locdescs = I18nManager.getInstance().getEnabledLanguagesTranslated();
Set<String> lkeys = locdescs.keySet();
String[] languageKeys = new String[lkeys.size() + 1];
String[] languageValues = new String[lkeys.size() + 1];
languageKeys[0] = "*";
languageValues[0] = translate("link.lang.all");
int p = 1;
for (Iterator<String> iter = lkeys.iterator(); iter.hasNext(); ) {
String key = iter.next();
languageKeys[p] = key;
languageValues[p] = locdescs.get(key);
p++;
}
language = uifactory.addDropdownSingleselect("link.language", formLayout, languageKeys, languageValues, null);
String langKey = portletLink.getLanguage();
if (Arrays.asList(languageKeys).contains(langKey)) {
language.select(langKey, true);
}
uifactory.addFormSubmitButton("save", formLayout);
}
Aggregations