use of org.olat.core.gui.components.form.flexible.elements.TextElement in project OpenOLAT by OpenOLAT.
the class GenericSelectionPropertyHandlerController method formOK.
@Override
protected void formOK(UserRequest ureq) {
// save the data to config
boolean m = modeRadio.isSelected(1);
handler.setMultiSelect(m);
List<String> selectionKeys = new ArrayList<String>();
for (int i = 0; i < optionFieldNames.size(); i++) {
TextElement te = (TextElement) hcFlc.getFormComponent(OPTFIELD_PREFIX + optionFieldNames.get(i));
String textValue = te.getValue();
if (StringHelper.containsNonWhitespace(textValue))
selectionKeys.add(textValue);
}
String[] selectionKeysArray = new String[selectionKeys.size()];
handler.setSelectionKeys(selectionKeys.toArray(selectionKeysArray));
handler.saveConfig();
// remove i18nKeys that are no longer used (prevent orphans)
if (singleKeyTrsCtrl == null) {
singleKeyTrsCtrl = new SingleKeyTranslatorController(ureq, getWindowControl(), "", GenericSelectionPropertyHandler.class);
}
for (String key : i18nKeysToDelete) {
singleKeyTrsCtrl.deleteI18nKey(key);
}
fireEvent(ureq, Event.DONE_EVENT);
}
use of org.olat.core.gui.components.form.flexible.elements.TextElement in project OpenOLAT by OpenOLAT.
the class ICQPropertyHandler method addFormItem.
/**
* @see org.olat.user.propertyhandlers.Generic127CharTextPropertyHandler#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, User user, String usageIdentifyer, boolean isAdministrativeUser, FormItemContainer formItemContainer) {
TextElement textElement = (TextElement) super.addFormItem(locale, user, usageIdentifyer, isAdministrativeUser, formItemContainer);
textElement.setMaxLength(ICQ_NAME_MAX_LENGTH);
if (!UserManager.getInstance().isUserViewReadOnly(usageIdentifyer, this) || isAdministrativeUser) {
textElement.setExampleKey("form.example.icqname", null);
}
return textElement;
}
use of org.olat.core.gui.components.form.flexible.elements.TextElement in project OpenOLAT by OpenOLAT.
the class MSNPropertyHandler method isValid.
/**
* @see org.olat.user.propertyhandlers.Generic127CharTextPropertyHandler#isValid(org.olat.core.gui.components.form.flexible.FormItem, java.util.Map)
*/
@Override
public boolean isValid(User user, FormItem formItem, Map<String, String> formContext) {
boolean result;
TextElement textElement = (TextElement) formItem;
if (StringHelper.containsNonWhitespace(textElement.getValue())) {
// Use an HttpClient to fetch a profile information page from MSN.
CloseableHttpClient httpClient = HttpClientFactory.getHttpClientInstance(false);
try {
URIBuilder uriBuilder = new URIBuilder(MSN_NAME_VALIDATION_URL);
uriBuilder.addParameter(MSN_NAME_URL_PARAMETER, textElement.getValue());
HttpGet httpMethod = new HttpGet(uriBuilder.build());
// Get the user profile page
HttpResponse response = httpClient.execute(httpMethod);
int httpStatusCode = response.getStatusLine().getStatusCode();
// Looking at the HTTP status code tells us whether a user with the given MSN name exists.
if (httpStatusCode == HttpStatus.SC_MOVED_PERMANENTLY) {
// If the user exists, we get a 301...
result = true;
} else if (httpStatusCode == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
// ...and if the user doesn't exist, MSN sends a 500.
textElement.setErrorKey("form.name.msn.error", null);
result = false;
} else {
// For HTTP status codes other than 301 and 500 we will assume that the given MSN name is valid, but inform the user about this.
textElement.setExampleKey("form.example.msnname.notvalidated", null);
log.warn("MSN name validation: Expected HTTP status 301 or 500, but got " + httpStatusCode);
result = true;
}
} catch (Exception e) {
// In case of any exception, assume that the given MSN name is valid (The opposite would block easily upon network problems), and inform the user about this.
textElement.setExampleKey("form.example.msnname.notvalidated", null);
log.warn("MSN name validation: Exception: " + e.getMessage());
result = true;
} finally {
IOUtils.closeQuietly(httpClient);
}
} else {
result = true;
}
return result;
}
use of org.olat.core.gui.components.form.flexible.elements.TextElement in project OpenOLAT by OpenOLAT.
the class UserNameReadOnlyPropertyHandler method addFormItem.
@Override
public FormItem addFormItem(Locale locale, User user, String usageIdentifyer, boolean isAdministrativeUser, FormItemContainer formItemContainer) {
TextElement tElem = null;
tElem = FormUIFactory.getInstance().addTextElement(getName(), i18nFormElementLabelKey(), 127, getInternalValue(user), formItemContainer);
tElem.setLabel(i18nFormElementLabelKey(), null);
// always read-only
tElem.setEnabled(false);
return tElem;
}
use of org.olat.core.gui.components.form.flexible.elements.TextElement in project OpenOLAT by OpenOLAT.
the class AttributeEasyRowAdderController method hasError.
/**
* Checks if this form produces an error
*
* @return true: has an error; false: is valid
*/
public boolean hasError() {
for (final Iterator<String> iterator = columnValueText.iterator(); iterator.hasNext(); ) {
final String name = iterator.next();
final TextElement tei = (TextElement) flc.getFormComponent(name);
if (tei.isVisible() && tei.getValue().trim().length() == 0) {
return true;
}
}
return false;
}
Aggregations