Example usage for org.apache.wicket.markup.html.form Form clearInput

List of usage examples for org.apache.wicket.markup.html.form Form clearInput

Introduction

In this page you can find the example usage for org.apache.wicket.markup.html.form Form clearInput.

Prototype

public final void clearInput() 

Source Link

Document

Clears the input from the form's nested children of type FormComponent .

Usage

From source file:com.servoy.extensions.beans.dbtreeview.table.InmethodDBTreeTableView.java

License:Open Source License

@Override
protected void onJunctionLinkClicked(AjaxRequestTarget target, Object node) {
    super.onJunctionLinkClicked(target, node);

    // we need to clear all inputs of the form,
    // because this onjunctionclicked is done by a form submit so all 
    // fields have there rawInput set.
    Form<?> form = getForm();
    if (form != null) {
        Form<?> rootForm = form.getRootForm();
        if (rootForm != null) {
            form = rootForm;// ww  w. j ava 2s .  com
        }
        if (!form.hasError()) {
            form.clearInput();
        }
    }
}

From source file:cz.zcu.kiv.eegdatabase.wui.ui.administration.components.ResearchGroupManagementForm.java

License:Apache License

/**
 * Adds form controls to a container (e.g. the form)
 * @param f the container the controls will be added to
  *///from  ww w .jav  a2 s.  c o m
private void addControls(WebMarkupContainer f) {
    Button button = new AjaxButton("submitButton", ResourceUtils.getModel("button.save")) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            super.onSubmit(target, form);
            researchGroupFacade.update(groupModel.getObject());

            info(ResourceUtils.getString("text.administration.group.changed",
                    groupModel.getObject().getTitle()));
            target.add(form, feedback);
        }

    };

    f.add(button);

    button = new AjaxButton("cancelButton", ResourceUtils.getModel("button.cancel")) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            super.onSubmit(target, form);
            form.clearInput();
            target.add(form);
        }

    };
    button.setDefaultFormProcessing(false);
    f.add(button);

}

From source file:cz.zcu.kiv.eegdatabase.wui.ui.licenses.components.LicenseEditForm.java

License:Apache License

/**
 * Add window controls - buttons, etc// w ww . ja  v a 2s . c o  m
 *
 * @param cont
 */
@SuppressWarnings("serial")
private void addControls() {
    saveButton = new AjaxButton("submitButton", ResourceUtils.getModel("button.save")) {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            onSubmitAction(LicenseEditForm.this.form.getModel(), target, form);
            target.add(form);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            super.onError(target, form);
            target.add(form);
        }

        @Override
        protected void onConfigure() {
            super.onConfigure();
            this.setVisible(displayControls);
        }
    };
    saveButton.setVisibilityAllowed(false);
    form.add(saveButton);

    AjaxButton button = new AjaxButton("cancelButton", ResourceUtils.getModel("button.cancel")) {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            onCancelAction(LicenseEditForm.this.form.getModel(), target, form);
            form.clearInput();
            target.add(form);
        }

        @Override
        protected void onConfigure() {
            super.onConfigure();
            this.setVisible(displayControls);
        }
    };
    button.setDefaultFormProcessing(false);
    form.add(button);

    /*button = new AjaxButton("removeButton", ResourceUtils.getModel("button.remove")) {
       @Override
       protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
    onRemoveAction(LicenseEditForm.this.form.getModel(), target, form);
       }
            
       @Override
       protected void onConfigure() {
    super.onConfigure();
    this.setVisible(displayControls && displayRemoveButton);
       }
    };
    form.add(button);*/
}

From source file:cz.zcu.kiv.eegdatabase.wui.ui.licenses.components.LicensePriceForm.java

License:Apache License

@SuppressWarnings("serial")
private void addControls() {

    // save button
    saveButton = new AjaxButton("submitButton", ResourceUtils.getModel("button.save")) {

        @Override// ww  w.java 2  s.  c  o  m
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            onSubmitAction(LicensePriceForm.this.form.getModelObject(), priceInput.getModelObject(), target,
                    form);
            target.add(form);
            clearForm();
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            super.onError(target, form);
            target.add(form);
            clearForm();
        }

    };

    saveButton.setVisibilityAllowed(false);
    form.add(saveButton);

    // cancel button
    AjaxButton cancelButton = new AjaxButton("cancelButton", ResourceUtils.getModel("button.cancel")) {

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            form.clearInput();
            onCancelAction(target, form);
            clearForm();
        }
    };

    cancelButton.setDefaultFormProcessing(false);
    form.add(cancelButton);
}

From source file:cz.zcu.kiv.eegdatabase.wui.ui.licenses.components.PersonalLicenseRejectPanel.java

License:Apache License

private void addControls() {
    Button b = new AjaxButton("submitButton", ResourceUtils.getModel("button.save")) {

        @Override//from   w  w  w. ja  va2s. c  o  m
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            super.onSubmit(target, form);
            PersonalLicenseRejectPanel.this.onSubmitAction(target);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            super.onError(target, form);
            target.add(form);
        }

    };
    form.add(b);

    b = new AjaxButton("cancelButton", ResourceUtils.getModel("button.cancel")) {

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            super.onSubmit(target, form);
            form.clearInput();
            PersonalLicenseRejectPanel.this.onCancelAction(target);
        }

    };
    b.setDefaultFormProcessing(false);
    form.add(b);
}

From source file:cz.zcu.kiv.eegdatabase.wui.ui.order.components.PromoCodePopupForm.java

License:Apache License

/**
 * Add window controls - buttons, etc/* www  . j  a  v a2  s  .c  o m*/
 *
 */
private void addControls() {
    AjaxButton button = new AjaxButton("submitButton", ResourceUtils.getModel("button.save")) {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            onSubmitAction(strWrapper, target, form);
            target.add(form);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            super.onError(target, form);
            target.add(form);
        }

        @Override
        protected void onConfigure() {
            super.onConfigure();
            this.setVisible(true);
        }
    };
    form.add(button);

    button = new AjaxButton("cancelButton", ResourceUtils.getModel("button.cancel")) {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            onCancelAction(strWrapper, target, form);
            form.clearInput();
            target.add(form);
        }

        @Override
        protected void onConfigure() {
            super.onConfigure();
            this.setVisible(true);
        }
    };
    button.setDefaultFormProcessing(false);
    form.add(button);

}

From source file:org.artifactory.webapp.wicket.page.security.profile.ProfilePage.java

License:Open Source License

private TitledAjaxSubmitLink createUpdateProfileButton(final Form form) {
    return new TitledAjaxSubmitLink("update", "Update", form) {
        @Override/*w w w.  j  av  a2s .  c om*/
        protected void onSubmit(AjaxRequestTarget target, Form form) {
            ProfileModel profile = getUserProfile();
            UserInfo userInfo = loadUserInfo();
            if (!StringUtils.hasText(profile.getEmail())) {
                error("Field 'Email address' is required.");
            } else if (StringUtils.hasText(profile.getBintrayUsername())
                    && !StringUtils.hasText(profile.getBintrayApiKey())) {
                error("Cannot save Bintray username without an API key.");
            } else if (StringUtils.hasText(profile.getBintrayApiKey())
                    && !StringUtils.hasText(profile.getBintrayUsername())) {
                error("Cannot save Bintray API key without username.");
            } else {
                MutableUserInfo mutableUser = InfoFactoryHolder.get().copyUser(userInfo);
                mutableUser.setEmail(profile.getEmail());
                mutableUser.setBintrayAuth(profile.getBintrayAuth());
                if (!authorizationService.isDisableInternalPassword()) {
                    String newPassword = profile.getNewPassword();
                    if (StringUtils.hasText(newPassword)) {
                        mutableUser.setPassword(securityService.generateSaltedPassword(newPassword));
                        profile.setCurrentPassword(newPassword);
                        profilePanel.displayEncryptedPassword(mutableUser);
                        if (mavenSettingsPanel != null
                                && !ConstantValues.uiHideEncryptedPassword.getBoolean()) {
                            mavenSettingsPanel.displayEncryptedPassword(mutableUser);
                            target.add(mavenSettingsPanel);
                        }
                    }
                }
                userGroupService.updateUser(mutableUser, !mutableUser.hasSameAuthorizationContext(userInfo));
                AccessLogger
                        .updated("User " + mutableUser.getUsername() + " has updated his profile successfully");
                info("Successfully updated profile '" + mutableUser.getUsername() + "'");
            }
            form.clearInput();
            target.add(profilePanel);
            AjaxUtils.refreshFeedback(target);

        }
    };
}

From source file:org.bosik.diacomp.web.frontend.wicket.pages.register.RegisterPage.java

License:Open Source License

@Override
protected void onInitialize() {
    super.onInitialize();

    feedbackPanel = new FeedbackPanel("feedbackPanel");
    feedbackPanel.setOutputMarkupId(true);
    add(feedbackPanel);/* w  w  w . j  a v  a  2s  . co  m*/

    final WebMarkupContainer progressContainer = new WebMarkupContainer("progressContainer");
    progressContainer.setOutputMarkupId(true);
    add(progressContainer);

    progressBehavior = new AjaxSelfUpdatingTimerBehavior(Duration.seconds(1)) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onPostProcessTarget(AjaxRequestTarget target) {
            if (progress.isRunning()) {
                progressSpinner.setVisible(true);
            } else {
                progressSpinner.setVisible(false);
                progressBehavior.stop(null);
                buttonRegister.setEnabled(true);
                target.add(buttonRegister);

                if (progress.isSuccess()) {
                    Page succeedPage = new RegistrationSentPage(Model.of(progress.getMessage()));
                    setResponsePage(succeedPage);
                } else {
                    feedbackPanel.error(progress.getMessage());
                    target.add(feedbackPanel);
                }
            }
        }
    };
    progressBehavior.stop(null);
    progressContainer.add(progressBehavior);

    progressSpinner = new WebMarkupContainer("progressSpinner");
    progressSpinner.setOutputMarkupId(true);
    progressSpinner.setVisible(false);
    progressContainer.add(progressSpinner);

    Form<Void> form = new Form<>("regForm");
    form.setOutputMarkupId(true);
    add(form);

    final TextField<String> fieldEmail = new TextField<>("rhCyIStebK", Model.of(""));
    fieldEmail.add(EmailAddressValidator.getInstance());
    form.add(fieldEmail);

    final HiddenField<String> fieldFakeEmail = new HiddenField<>("email", Model.of(""));
    form.add(fieldFakeEmail);

    final PasswordTextField fieldPassword = new PasswordTextField("P2BohS6rUR", Model.of(""));
    fieldPassword.setRequired(false); // to handle it manually
    form.add(fieldPassword);

    form.add(new BookmarkablePageLink<Void>("linkEula", EulaPage.class));
    form.add(new BookmarkablePageLink<Void>("linkPrivacy", PrivacyPolicyPage.class));

    buttonRegister = new AjaxFallbackButton("buttonRegister", form) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            final String antiBot = fieldFakeEmail.getModelObject();
            if (antiBot != null && !antiBot.isEmpty()) {
                form.clearInput();
                return;
            }

            final WebRequest request = (WebRequest) RequestCycle.get().getRequest();
            final String challenge = request.getPostParameters().getParameterValue("g-recaptcha-response")
                    .toString();
            final String secret = Config.get(Config.KEY_CAPTCHA_SECRET);

            final String MSG_ERROR_CAPTCHA = getString("error.captcha");
            final String MSG_ERROR_EMAIL = getString("error.wrongEmail");
            final String MSG_ERROR_DUPLICATION = getString("error.emailInUse");
            final String MSG_ERROR_PASSWORD_IS_EMPTY = getString("error.password.empty");
            final String MSG_ERROR_PASSWORD_TOO_SHORT = getString("error.password.tooShort");
            final String MSG_ERROR_PASSWORD_TOO_LONG = getString("error.password.tooLong");
            final String MSG_ERROR_USERNAME_IS_EMPTY = getString("error.userName.empty");
            final String MSG_ERROR_USERNAME_TOO_SHORT = getString("error.userName.tooShort");
            final String MSG_ERROR_USERNAME_TOO_LONG = getString("error.userName.tooLong");
            final String MSG_ERROR_COMMON = getString("error.common");

            final String appUrlRaw = Config.get(Config.KEY_APP_URL);
            final String appUrl = appUrlRaw.endsWith("/") ? appUrlRaw : appUrlRaw + "/";
            final String bodyPattern = getString("email.body");
            final String title = getString("email.title");
            final String sender = getString("email.sender");

            progressBehavior.restart(target);
            buttonRegister.setEnabled(false);
            progressSpinner.setVisible(true);
            Session.get().getFeedbackMessages().clear();
            target.add(buttonRegister, progressSpinner, feedbackPanel);

            new Thread() {
                @Override
                public void run() {
                    try {
                        progress = new ProgressBundle();
                        progress.setRunning(true);

                        if (!Utils.validateCaptcha(secret, challenge)) {
                            progress.fail(MSG_ERROR_CAPTCHA);
                            return;
                        }

                        String email = fieldEmail.getModelObject();
                        String password = fieldPassword.getModelObject();

                        if (!StringUtils.isEmpty(email)) {
                            email = email.toLowerCase();
                        }

                        String activationKey = authService.register(email, password);
                        String activationLink = String.format("%sregister/activate?key=%s", appUrl,
                                activationKey);
                        String body = String.format(bodyPattern, activationLink, activationLink);
                        Utils.sendEmail(email, title, body, sender);

                        progress.success(email);
                    } catch (UserNameIsEmptyException e) {
                        progress.fail(MSG_ERROR_USERNAME_IS_EMPTY);
                    } catch (UserNameTooShortException e) {
                        progress.fail(MSG_ERROR_USERNAME_TOO_SHORT);
                    } catch (UserNameTooLongException e) {
                        progress.fail(MSG_ERROR_USERNAME_TOO_LONG);
                    } catch (PasswordIsEmptyException e) {
                        progress.fail(MSG_ERROR_PASSWORD_IS_EMPTY);
                    } catch (PasswordTooShortException e) {
                        progress.fail(MSG_ERROR_PASSWORD_TOO_SHORT);
                    } catch (PasswordTooLongException e) {
                        progress.fail(MSG_ERROR_PASSWORD_TOO_LONG);
                    } catch (MessagingException e) {
                        progress.fail(MSG_ERROR_EMAIL);
                    } catch (DuplicateException e) {
                        progress.fail(MSG_ERROR_DUPLICATION);
                    } catch (Exception e) {
                        e.printStackTrace();
                        progress.fail(MSG_ERROR_COMMON);
                    }
                }
            }.start();
        }
    };
    buttonRegister.setOutputMarkupId(true);
    form.add(buttonRegister);
}

From source file:org.jaulp.wicket.dialogs.ajax.modal.BaseModalPanel.java

License:Apache License

/**
 * Instantiates a new base modal panel./*from   w  w w  .j a  v a 2 s .c  o  m*/
 *
 * @param id
 *            the id
 * @param model
 *            the model
 */
public BaseModalPanel(final String id, final CompoundPropertyModel<T> model) {
    super(id);

    final Form<T> form = new Form<>("form", model);
    form.setOutputMarkupId(true);
    form.clearInput();
    add(form);

    final TextArea<String> note = new TextArea<>("messageContent");

    note.clearInput();
    // IT IS VERY IMPORTANT TO SET THE OUTPUTMARKUPID TO TRUE...
    note.setOutputMarkupId(true);
    note.add(new OnChangeAjaxBehavior() {
        /**
         * The serialVersionUID.
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void onUpdate(final AjaxRequestTarget target) {
            // Do nothing...
        }
    });
    form.add(note);

    final AjaxButton close = new AjaxButton("cancelButton") {
        /**
         * The serialVersionUID.
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
            target.add(note);
            onCancel(target);

        }

        @SuppressWarnings("unused")
        public <E extends EventObject> void send(final IEventSink sink, final Broadcast broadcast,
                final E payload) {
            // TODO Auto-generated method stub

        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            // TODO Auto-generated method stub

        }
    };
    form.add(close);

    final AjaxButton selectionButton = new AjaxButton("okButton") {
        /**
         * The serialVersionUID.
         */
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
            final T obj = model.getObject();
            onSelect(target, obj);
        }

        @SuppressWarnings("unused")
        public <E extends EventObject> void send(IEventSink sink, Broadcast broadcast, E payload) {
            // TODO Auto-generated method stub

        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            // TODO Auto-generated method stub

        }
    };
    form.add(selectionButton);

}

From source file:org.openengsb.ui.admin.userService.UserService.java

License:Apache License

private void initContent() {
    final WebMarkupContainer usermanagementContainer = new WebMarkupContainer("usermanagementContainer");
    usermanagementContainer.setOutputMarkupId(true);

    final Form<UserInput> userForm = new Form<UserInput>("form") {
        private static final long serialVersionUID = 6420993810725159979L;

        @Override/*from w w w.  ja  v a2 s.c o m*/
        protected void onSubmit() {
            createUser();
        }
    };

    usernameField = new RequiredTextField<String>("username");
    passwordField = new PasswordTextField("password");
    passwordVerficationField = new PasswordTextField("passwordVerification");
    usernameField.setOutputMarkupId(true);
    passwordField.setOutputMarkupId(true);
    passwordVerficationField.setOutputMarkupId(true);

    rolesField = new TextField<String>("roles");
    rolesField.setOutputMarkupId(true);

    userForm.add(usernameField);
    userForm.add(passwordField);
    userForm.add(passwordVerficationField);
    userForm.add(rolesField);

    userForm.setModel(new CompoundPropertyModel<UserInput>(input));

    FeedbackPanel feedbackPanel = new FeedbackPanel("feedback");
    feedbackPanel.setOutputMarkupId(true);

    userForm.add(feedbackPanel);

    AjaxButton resetButton = new AjaxButton("resetbutton") {
        private static final long serialVersionUID = 7997862317008905740L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            input.setPassword("");
            input.setUsername("");
            input.setPasswordVerification("");
            input.setRoles("");
            form.clearInput();
            usernameField.setEnabled(true);
            editMode = false;
            target.addComponent(usermanagementContainer);
        }
    };

    resetButton.setDefaultFormProcessing(false);
    userForm.add(resetButton);

    IModel<List<User>> userList = new LoadableDetachableModel<List<User>>() {
        private static final long serialVersionUID = 2579825372351310299L;

        @Override
        protected List<User> load() {
            try {
                return userManager.getAllUser();
            } catch (UserManagementException e) {
                error(new StringResourceModel("userManagementExceptionError", null).getString());
            }
            return new ArrayList<User>();
        }
    };
    ListView<User> users = new ListView<User>("users", userList) {
        private static final long serialVersionUID = 7628860457238288128L;

        @Override
        protected void populateItem(final ListItem<User> userListItem) {
            userListItem.add(new Label("user.name", userListItem.getModelObject().getUsername()));
            userListItem.add(new AjaxLink<User>("user.delete") {
                private static final long serialVersionUID = 2004369349622394213L;

                @Override
                public void onClick(AjaxRequestTarget ajaxRequestTarget) {
                    try {
                        userManager.deleteUser(userListItem.getModelObject().getUsername());
                        getList().remove(userListItem.getModelObject());
                        ajaxRequestTarget.addComponent(usermanagementContainer);
                    } catch (UserManagementException e) {
                        error(new StringResourceModel("userManagementExceptionError", this, null).getString());
                    }
                }
            });
            userListItem.add(new AjaxLink<User>("user.update") {
                private static final long serialVersionUID = -2327085637957255085L;

                @Override
                public void onClick(AjaxRequestTarget ajaxRequestTarget) {
                    input.setUsername(userListItem.getModelObject().getUsername());
                    input.setPassword(userListItem.getModelObject().getPassword());
                    input.setPasswordVerification(userListItem.getModelObject().getPassword());
                    input.setRoles(makeCommaSeparatedList(userListItem.getModelObject().getAuthorities()));
                    editMode = true;
                    usernameField.setEnabled(false);
                    ajaxRequestTarget.addComponent(usermanagementContainer);
                }
            });
        }
    };
    users.setOutputMarkupId(true);

    usermanagementContainer.add(users);
    usermanagementContainer.add(userForm);
    add(usermanagementContainer);
}