use of org.apache.wicket.markup.html.form.TextField in project wicket by apache.
the class AjaxFormValidatingBehaviorTestPage method addFormWithOrdinaryFeedbackPanel.
private void addFormWithOrdinaryFeedbackPanel() {
Form<Void> form = new Form<>("form1");
form.add(new AjaxFormValidatingBehavior("blur"));
form.add(new FeedbackPanel("feedback", new ContainerFeedbackMessageFilter(form)).setOutputMarkupId(true));
add(form);
TextField<String> input = new TextField<>("input", new Model<String>());
input.setRequired(true);
form.add(input);
}
use of org.apache.wicket.markup.html.form.TextField in project wicket by apache.
the class AjaxEditableLabel method newEditor.
/**
* Create a new form component instance to serve as editor.
*
* @param parent
* The parent component
* @param componentId
* Id that should be used by the component
* @param model
* The model
* @return The editor
*/
protected FormComponent<T> newEditor(final MarkupContainer parent, final String componentId, final IModel<T> model) {
TextField<T> editor = new TextField<T>(componentId, model) {
private static final long serialVersionUID = 1L;
@Override
public <C> IConverter<C> getConverter(final Class<C> type) {
IConverter<C> c = AjaxEditableLabel.this.getConverter(type);
return c != null ? c : super.getConverter(type);
}
@Override
protected void onModelChanged() {
super.onModelChanged();
AjaxEditableLabel.this.onModelChanged();
}
@Override
protected void onModelChanging() {
super.onModelChanging();
AjaxEditableLabel.this.onModelChanging();
}
};
editor.setOutputMarkupId(true);
editor.setVisible(false);
editor.add(new EditorAjaxBehavior() {
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
super.updateAjaxAttributes(attributes);
attributes.setEventNames("blur", "keyup", "keydown");
// Note: preventDefault is handled selectively below
attributes.setPreventDefault(false);
// Note: escape can be detected on keyup, enter can be detected on keyup
CharSequence precondition = "var kc=Wicket.Event.keyCode(attrs.event)," + "evtType=attrs.event.type," + "ret=false;" + "if (evtType==='blur' || (evtType==='keyup' && kc===27) || (evtType==='keydown' && kc===13)) {attrs.event.preventDefault(); ret = true;}" + "return ret;";
AjaxCallListener ajaxCallListener = new AjaxCallListener();
ajaxCallListener.onPrecondition(precondition);
CharSequence dynamicExtraParameters = "var result," + "evtType=attrs.event.type;" + "if (evtType === 'keyup') { result = { 'save': false }; }" + "else { result = { 'save': true }; }" + "return result;";
attributes.getDynamicExtraParameters().add(dynamicExtraParameters);
attributes.getAjaxCallListeners().add(ajaxCallListener);
}
});
return editor;
}
use of org.apache.wicket.markup.html.form.TextField in project openmeetings by apache.
the class RoomForm method onInitialize.
@Override
protected void onInitialize() {
super.onInitialize();
RequiredTextField<String> name = new RequiredTextField<>("name");
name.setLabel(new Model<>(getString("165")));
add(name);
add(new //
DropDownChoice<>(//
"capacity", //
DROPDOWN_NUMBER_OF_PARTICIPANTS, new ChoiceRenderer<Long>() {
private static final long serialVersionUID = 1L;
@Override
public Object getDisplayValue(Long id) {
return id;
}
@Override
public String getIdValue(Long id, int index) {
return "" + id;
}
}));
add(new RoomTypeDropDown("type").setRequired(true).setLabel(Model.of(getString("45"))));
add(new TextArea<String>("comment"));
boolean isGroupAdmin = hasGroupAdminLevel(getRights());
add(new CheckBox("appointment").setEnabled(false));
add(new CheckBox("ispublic").setEnabled(!isGroupAdmin));
List<Group> orgList = isGroupAdmin ? groupDao.get(null, getUserId(), 0, Integer.MAX_VALUE, null) : groupDao.get(0, Integer.MAX_VALUE);
final List<RoomGroup> orgRooms = new ArrayList<>(orgList.size());
for (Group org : orgList) {
orgRooms.add(new RoomGroup(org, getModelObject()));
}
add(new Select2MultiChoice<>("groups", null, new RestrictiveChoiceProvider<RoomGroup>() {
private static final long serialVersionUID = 1L;
@Override
public String getDisplayValue(RoomGroup choice) {
String name = choice.getGroup().getName();
return name == null ? "" : name;
}
@Override
public String toId(RoomGroup choice) {
Long id = choice.getGroup().getId();
return id == null ? null : "" + id;
}
@Override
public void query(String term, int page, Response<RoomGroup> response) {
response.addAll(orgRooms.stream().filter(rg -> Strings.isEmpty(term) || rg.getGroup().getName().contains(term)).collect(Collectors.toList()));
}
@Override
public RoomGroup fromId(String _id) {
Long id = Long.valueOf(_id);
if (!orgList.stream().filter(g -> g.getId().equals(id)).findFirst().isPresent()) {
// seems to be hacked
return null;
}
Group g = groupDao.get(id);
return new RoomGroup(g, RoomForm.this.getModelObject());
}
}).setLabel(Model.of(getString("828"))).setRequired(isGroupAdmin));
add(new CheckBox("isDemoRoom"));
TextField<Integer> demoTime = new TextField<>("demoTime");
demoTime.setLabel(new Model<>(getString("637")));
add(demoTime);
add(new CheckBox("allowUserQuestions"));
add(new CheckBox("audioOnly"));
add(new CheckBox("closed"));
add(new TextField<String>("redirectURL"));
add(new CheckBox("waitForRecording"));
add(new CheckBox("allowRecording"));
add(new CheckBox("chatModerated"));
add(new Select2MultiChoice<>("hiddenElements", null, new ChoiceProvider<RoomElement>() {
private static final long serialVersionUID = 1L;
@Override
public String getDisplayValue(RoomElement choice) {
return choice.name();
}
@Override
public String getIdValue(RoomElement choice) {
return choice.name();
}
@Override
public void query(String term, int page, Response<RoomElement> response) {
for (RoomElement r : RoomElement.values()) {
if (Strings.isEmpty(term) || r.name().contains(term)) {
response.add(r);
}
}
}
@Override
public Collection<RoomElement> toChoices(Collection<String> ids) {
Collection<RoomElement> rights = new ArrayList<>(ids.size());
for (String id : ids) {
rights.add(RoomElement.valueOf(id));
}
return rights;
}
}));
add(new CheckBox("chatOpened"));
add(new CheckBox("filesOpened"));
add(new CheckBox("autoVideoSelect"));
// Moderators
final Select2Choice<User> moderatorChoice = new Select2Choice<>("moderator2add", moderator2add, new AdminUserChoiceProvider() {
private static final long serialVersionUID = 1L;
@Override
public void query(String term, int page, Response<User> response) {
response.addAll(userDao.get(term, false, page * PAGE_SIZE, PAGE_SIZE));
response.setHasMore(PAGE_SIZE == response.getResults().size());
}
@Override
public String getDisplayValue(User choice) {
Address a = choice.getAddress();
return String.format("\"%s %s\" <%s>", choice.getFirstname(), choice.getLastname(), a == null ? "" : a.getEmail());
}
});
moderatorChoice.getSettings().setCloseOnSelect(true);
add(moderatorChoice.add(new AjaxFormComponentUpdatingBehavior("change") {
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
Room r = RoomForm.this.getModelObject();
User u = moderator2add.getObject();
boolean found = false;
if (u != null) {
if (r.getModerators() == null) {
r.setModerators(new ArrayList<RoomModerator>());
}
for (RoomModerator rm : r.getModerators()) {
if (rm.getUser().getId().equals(u.getId())) {
found = true;
break;
}
}
if (!found) {
RoomModerator rm = new RoomModerator();
rm.setRoomId(r.getId());
rm.setUser(u);
r.getModerators().add(0, rm);
moderator2add.setObject(null);
target.add(moderatorContainer, moderatorChoice);
}
}
}
}).setOutputMarkupId(true));
add(moderatorContainer.add(new ListView<RoomModerator>("moderators") {
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(final ListItem<RoomModerator> item) {
RoomModerator moderator = item.getModelObject();
Label name = new Label("uName", moderator.getUser().getFirstname() + " " + moderator.getUser().getLastname());
if (moderator.getId() == null) {
name.add(AttributeModifier.append(ATTR_CLASS, "newItem"));
}
item.add(new CheckBox("superModerator", new PropertyModel<Boolean>(moderator, "superModerator"))).add(new Label("userId", "" + moderator.getUser().getId())).add(name).add(new Label("email", moderator.getUser().getAddress().getEmail())).add(new ConfirmableAjaxBorder("delete", getString("80"), getString("833")) {
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target) {
RoomForm.this.getModelObject().getModerators().remove(item.getIndex());
target.add(moderatorContainer);
}
});
}
}).setOutputMarkupId(true));
add(new CheckBox("moderated"));
// Files
Form<Void> filesForm = new Form<>("filesForm");
add(filesForm.add(new Select2MultiChoice<>("files2add", files2add, new ChoiceProvider<BaseFileItem>() {
private static final long serialVersionUID = 1L;
@Override
public String getDisplayValue(BaseFileItem f) {
return f.getName();
}
@Override
public String getIdValue(BaseFileItem f) {
return "" + f.getId();
}
@Override
public void query(String term, int page, Response<BaseFileItem> response) {
response.addAll(fileDao.getAllRoomFiles(term, page * PAGE_SIZE, PAGE_SIZE, RoomForm.this.getModelObject().getId(), orgList));
response.setHasMore(PAGE_SIZE == response.getResults().size());
}
@Override
public Collection<BaseFileItem> toChoices(Collection<String> ids) {
return fileDao.get(ids);
}
}).setLabel(Model.of(getString("245")))).add(new TextField<Long>("wbidx", wbIdx) {
private static final long serialVersionUID = 1L;
@Override
protected String[] getInputTypes() {
return new String[] { "number" };
}
}).add(new AjaxButton("addFiles") {
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target) {
Room r = RoomForm.this.getModelObject();
if (r.getFiles() == null) {
r.setFiles(new ArrayList<>());
}
for (BaseFileItem f : files2add.getObject()) {
r.getFiles().add(new RoomFile(r.getId(), f, wbIdx.getObject()));
}
target.add(filesContainer, filesForm);
}
@Override
protected String getIcon() {
return JQueryIcon.PLUSTHICK;
}
}).setOutputMarkupId(true));
add(filesContainer.add(new ListView<RoomFile>("files") {
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(final ListItem<RoomFile> item) {
final RoomFile rf = item.getModelObject();
item.add(new Label("name", new PropertyModel<>(rf.getFile(), "name"))).add(new Label("wbIdx", new PropertyModel<>(rf, "wbIdx"))).add(new ConfirmableAjaxBorder("delete", getString("80"), getString("833")) {
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target) {
Room r = RoomForm.this.getModelObject();
for (Iterator<RoomFile> iter = r.getFiles().iterator(); iter.hasNext(); ) {
RoomFile _rf = iter.next();
if (_rf.getFile().getId().equals(rf.getFile().getId())) {
iter.remove();
break;
}
}
target.add(filesContainer);
}
});
}
}).setOutputMarkupId(true));
// Users in this Room
add(clientsContainer.add(clients.setOutputMarkupId(true)).setOutputMarkupId(true));
add(new TextField<String>("confno").setEnabled(false));
add(pin);
pin.setEnabled(getModelObject().isSipEnabled());
add(new TextField<String>("ownerId").setEnabled(false));
add(new AjaxCheckBox("sipEnabled") {
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
updateView(target);
}
}.setOutputMarkupId(true));
// attach an ajax validation behavior to all form component's keydown
// event and throttle it down to once per second
add(new AjaxFormValidatingBehavior("keydown", Duration.ONE_SECOND));
}
use of org.apache.wicket.markup.html.form.TextField in project gitblit by gitblit.
the class EditUserPage method setupPage.
protected void setupPage(final UserModel userModel) {
if (isCreate) {
super.setupPage(getString("gb.newUser"), "");
} else {
super.setupPage(getString("gb.edit"), userModel.username);
}
final Model<String> confirmPassword = new Model<String>(StringUtils.isEmpty(userModel.password) ? "" : userModel.password);
CompoundPropertyModel<UserModel> model = new CompoundPropertyModel<UserModel>(userModel);
// build list of projects including all repositories wildcards
List<String> repos = getAccessRestrictedRepositoryList(true, userModel);
List<String> userTeams = new ArrayList<String>();
for (TeamModel team : userModel.teams) {
userTeams.add(team.name);
}
Collections.sort(userTeams);
final String oldName = userModel.username;
final List<RegistrantAccessPermission> permissions = app().repositories().getUserAccessPermissions(userModel);
final Palette<String> teams = new Palette<String>("teams", new ListModel<String>(new ArrayList<String>(userTeams)), new CollectionModel<String>(app().users().getAllTeamNames()), new StringChoiceRenderer(), 10, false);
Locale locale = userModel.getPreferences().getLocale();
List<Language> languages = UserPage.getLanguages();
Language preferredLanguage = UserPage.getPreferredLanguage(locale, languages);
final IModel<Language> language = Model.of(preferredLanguage);
Form<UserModel> form = new Form<UserModel>("editForm", model) {
private static final long serialVersionUID = 1L;
/*
* (non-Javadoc)
*
* @see org.apache.wicket.markup.html.form.Form#onSubmit()
*/
@Override
protected void onSubmit() {
if (StringUtils.isEmpty(userModel.username)) {
error(getString("gb.pleaseSetUsername"));
return;
}
Language lang = language.getObject();
if (lang != null) {
userModel.getPreferences().setLocale(lang.code);
}
// force username to lower-case
userModel.username = userModel.username.toLowerCase();
String username = userModel.username;
if (isCreate) {
UserModel model = app().users().getUserModel(username);
if (model != null) {
error(MessageFormat.format(getString("gb.usernameUnavailable"), username));
return;
}
}
boolean rename = !StringUtils.isEmpty(oldName) && !oldName.equalsIgnoreCase(username);
if (app().authentication().supportsCredentialChanges(userModel)) {
if (!userModel.password.equals(confirmPassword.getObject())) {
error(getString("gb.passwordsDoNotMatch"));
return;
}
String password = userModel.password;
if (!PasswordHash.isHashedEntry(password)) {
// This is a plain text password.
// Check length.
int minLength = app().settings().getInteger(Keys.realm.minPasswordLength, 5);
if (minLength < 4) {
minLength = 4;
}
if (password.trim().length() < minLength) {
// TODO: Why do we trim here, but not in EditUserDialog and ChangePasswordPage?
error(MessageFormat.format(getString("gb.passwordTooShort"), minLength));
return;
}
// change the cookie
userModel.cookie = userModel.createCookie();
// Optionally store the password MD5 digest.
String type = app().settings().getString(Keys.realm.passwordStorage, PasswordHash.getDefaultType().name());
PasswordHash pwdh = PasswordHash.instanceOf(type);
if (pwdh != null) {
// Hash the password
userModel.password = pwdh.toHashedEntry(password, username);
}
} else if (rename && password.toUpperCase().startsWith(PasswordHash.Type.CMD5.name())) {
error(getString("gb.combinedMd5Rename"));
return;
}
}
// update user permissions
for (RegistrantAccessPermission repositoryPermission : permissions) {
if (repositoryPermission.mutable) {
userModel.setRepositoryPermission(repositoryPermission.registrant, repositoryPermission.permission);
}
}
Iterator<String> selectedTeams = teams.getSelectedChoices();
userModel.teams.clear();
while (selectedTeams.hasNext()) {
TeamModel team = app().users().getTeamModel(selectedTeams.next());
if (team == null) {
continue;
}
userModel.teams.add(team);
}
try {
if (isCreate) {
app().gitblit().addUser(userModel);
} else {
app().gitblit().reviseUser(oldName, userModel);
}
} catch (GitBlitException e) {
error(e.getMessage());
return;
}
setRedirect(false);
if (isCreate) {
// create another user
info(MessageFormat.format(getString("gb.userCreated"), userModel.username));
setResponsePage(EditUserPage.class);
} else {
// back to users page
setResponsePage(UsersPage.class);
}
}
};
// do not let the browser pre-populate these fields
form.add(new SimpleAttributeModifier("autocomplete", "off"));
// not all user providers support manipulating username and password
boolean editCredentials = app().authentication().supportsCredentialChanges(userModel);
// not all user providers support manipulating display name
boolean editDisplayName = app().authentication().supportsDisplayNameChanges(userModel);
// not all user providers support manipulating email address
boolean editEmailAddress = app().authentication().supportsEmailAddressChanges(userModel);
// not all user providers support manipulating team memberships
boolean editTeams = app().authentication().supportsTeamMembershipChanges(userModel);
// not all user providers support manipulating the admin role
boolean changeAdminRole = app().authentication().supportsRoleChanges(userModel, Role.ADMIN);
// not all user providers support manipulating the create role
boolean changeCreateRole = app().authentication().supportsRoleChanges(userModel, Role.CREATE);
// not all user providers support manipulating the fork role
boolean changeForkRole = app().authentication().supportsRoleChanges(userModel, Role.FORK);
// field names reflective match UserModel fields
form.add(new TextField<String>("username").setEnabled(editCredentials));
NonTrimmedPasswordTextField passwordField = new NonTrimmedPasswordTextField("password");
passwordField.setResetPassword(false);
form.add(passwordField.setEnabled(editCredentials));
NonTrimmedPasswordTextField confirmPasswordField = new NonTrimmedPasswordTextField("confirmPassword", confirmPassword);
confirmPasswordField.setResetPassword(false);
form.add(confirmPasswordField.setEnabled(editCredentials));
form.add(new TextField<String>("displayName").setEnabled(editDisplayName));
form.add(new TextField<String>("emailAddress").setEnabled(editEmailAddress));
DropDownChoice<Language> choice = new DropDownChoice<Language>("language", language, languages);
form.add(choice.setEnabled(languages.size() > 0));
if (userModel.canAdmin() && !userModel.canAdmin) {
// user inherits Admin permission
// display a disabled-yet-checked checkbox
form.add(new CheckBox("canAdmin", Model.of(true)).setEnabled(false));
} else {
form.add(new CheckBox("canAdmin").setEnabled(changeAdminRole));
}
if (userModel.canFork() && !userModel.canFork) {
// user inherits Fork permission
// display a disabled-yet-checked checkbox
form.add(new CheckBox("canFork", Model.of(true)).setEnabled(false));
} else {
final boolean forkingAllowed = app().settings().getBoolean(Keys.web.allowForking, true);
form.add(new CheckBox("canFork").setEnabled(forkingAllowed && changeForkRole));
}
if (userModel.canCreate() && !userModel.canCreate) {
// user inherits Create permission
// display a disabled-yet-checked checkbox
form.add(new CheckBox("canCreate", Model.of(true)).setEnabled(false));
} else {
form.add(new CheckBox("canCreate").setEnabled(changeCreateRole));
}
form.add(new CheckBox("excludeFromFederation"));
form.add(new CheckBox("disabled"));
form.add(new RegistrantPermissionsPanel("repositories", RegistrantType.REPOSITORY, repos, permissions, getAccessPermissions()));
form.add(teams.setEnabled(editTeams));
form.add(new TextField<String>("organizationalUnit").setEnabled(editDisplayName));
form.add(new TextField<String>("organization").setEnabled(editDisplayName));
form.add(new TextField<String>("locality").setEnabled(editDisplayName));
form.add(new TextField<String>("stateProvince").setEnabled(editDisplayName));
form.add(new TextField<String>("countryCode").setEnabled(editDisplayName));
form.add(new Button("save"));
Button cancel = new Button("cancel") {
private static final long serialVersionUID = 1L;
@Override
public void onSubmit() {
setResponsePage(UsersPage.class);
}
};
cancel.setDefaultFormProcessing(false);
form.add(cancel);
add(form);
}
use of org.apache.wicket.markup.html.form.TextField in project midpoint by Evolveum.
the class PageSizePopover method initLayout.
protected void initLayout() {
Button popButton = new Button(ID_POP_BUTTON);
popButton.setOutputMarkupId(true);
add(popButton);
WebMarkupContainer popover = new WebMarkupContainer(ID_POPOVER);
popover.setOutputMarkupId(true);
add(popover);
Form<?> form = new MidpointForm<>(ID_FORM);
popover.add(form);
AjaxSubmitButton button = new AjaxSubmitButton(ID_BUTTON) {
@Override
protected void onError(AjaxRequestTarget target) {
super.onError(target);
target.add(getPageBase().getFeedbackPanel());
}
@Override
protected void onSubmit(AjaxRequestTarget target) {
super.onSubmit(target);
pageSizeChanged(target);
}
};
form.add(button);
TextField<?> input = new TextField<>(ID_INPUT, createInputModel());
input.add(new RangeValidator<>(5, 100));
input.setLabel(createStringResource("PageSizePopover.title"));
input.add(new SearchFormEnterBehavior(button));
input.setType(Integer.class);
form.add(input);
}
Aggregations