setFormDescription("form.description");
this.formContext.put("username", this.identity.getName());
// Add the noneditable username field.
MultipleSelectionElement usernameCheckbox = uifactory.addCheckboxesHorizontal("checkbox_username", null, formLayout, new String[] {"checkbox_username"}, new String[] {""}, null);
usernameCheckbox.select("checkbox_username", true);
usernameCheckbox.setEnabled(false);
StaticTextElement usernameText = uifactory.addStaticTextElement("username", this.identity.getName(), formLayout);
usernameText.setMandatory(true);
this.formItems.put("username", usernameText);
String currentGroup = null;
List<UserPropertyHandler> homepagePropertyHanders = UserManager.getInstance().getUserPropertyHandlersFor(HomePageConfig.class.getCanonicalName(), isAdministrativeUser);
// show a form element for each property handler
for (UserPropertyHandler userPropertyHandler : this.userPropertyHandlers) {
if (userPropertyHandler == null) {
continue;
}
// add spacer if necessary (i.e. when group name changes)
String group = userPropertyHandler.getGroup();
if (!group.equals(currentGroup)) {
if (currentGroup != null) {
SpacerElement spacerElement = uifactory.addSpacerElement("spacer_" + group, formLayout, false);
this.formItems.put("spacer_" + group, spacerElement);
}
currentGroup = group;
}
if (homepagePropertyHanders.contains(userPropertyHandler)) {
// add checkbox to container if configured for homepage usage identifier
String checkboxName = "checkbox_" + userPropertyHandler.getName();
MultipleSelectionElement publishCheckbox = uifactory.addCheckboxesHorizontal(checkboxName, null, formLayout, new String[] {userPropertyHandler.i18nFormElementLabelKey()}, new String[] {""}, null);
this.publishCheckboxes.put(checkboxName, publishCheckbox);
boolean isEnabled = this.conf.isEnabled(userPropertyHandler.getName());
if (isEnabled) {
publishCheckbox.select(userPropertyHandler.i18nFormElementLabelKey(), true);
} else {
publishCheckbox.select(userPropertyHandler.i18nFormElementLabelKey(), false);
}
// Mandatory homepage properties can not be changed by user
UserManager um = UserManager.getInstance();
if (um.isMandatoryUserProperty(HomePageConfig.class.getCanonicalName(), userPropertyHandler)) {
publishCheckbox.select(userPropertyHandler.i18nFormElementLabelKey(), true);
publishCheckbox.setEnabled(false);
}
} else {
uifactory.addSpacerElement("spacer_" + userPropertyHandler.getName(), formLayout, true);
}
// add input field to container
FormItem formItem = userPropertyHandler.addFormItem(getLocale(), this.identity.getUser(), this.usageIdentifier, this.isAdministrativeUser, formLayout);
String propertyName = userPropertyHandler.getName();
this.formItems.put(propertyName, formItem);
if (formItem instanceof TextElement) {
// it's a text field, so get the value of this property into the text field
TextElement textElement = (TextElement)formItem;
textElement.setValue(this.identity.getUser().getProperty(propertyName, getLocale()));
} else if (formItem instanceof MultipleSelectionElement) {
// it's a checkbox, so set the box to checked if the corresponding property is set to "true"
MultipleSelectionElement checkbox = (MultipleSelectionElement)formItem;
String value = this.identity.getUser().getProperty(propertyName, getLocale());
if (value != null) {
checkbox.select(propertyName, value.equals("true"));
} else {
// assume "false" if the property is not present
checkbox.select(propertyName, false);
}
}
// special case for email field
if (userPropertyHandler.getName().equals("email")) {