Example usage for org.apache.wicket.ajax.attributes AjaxRequestAttributes setPreventDefault

List of usage examples for org.apache.wicket.ajax.attributes AjaxRequestAttributes setPreventDefault

Introduction

In this page you can find the example usage for org.apache.wicket.ajax.attributes AjaxRequestAttributes setPreventDefault.

Prototype

public AjaxRequestAttributes setPreventDefault(boolean preventDefault) 

Source Link

Document

Only applies for event behaviors.

Usage

From source file:com.googlecode.wicket.kendo.ui.widget.menu.form.MenuItemAjaxButton.java

License:Apache License

@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
    super.updateAjaxAttributes(attributes);

    attributes.setPreventDefault(false); // wicket7
    attributes.setEventPropagation(EventPropagation.BUBBLE);
}

From source file:guru.mmp.application.web.template.components.ExtensibleFormDialogImplementation.java

License:Apache License

/**
 * Returns the buttons associated with the extensible dialog.
 *
 * @return the buttons associated with the extensible dialog
 *///from   w  w w  .  ja  v  a  2  s.com
@Override
protected List<ExtensibleDialogButton> getButtons() {
    ExtensibleDialogButton cancelButton = new ExtensibleDialogButton(cancelText);

    cancelButton.add(new AjaxEventBehavior("click") {
        @Override
        protected void onEvent(AjaxRequestTarget target) {
            System.out.println("[DEBUG][cancelButton][onSubmit] HERE!!!!");

            ExtensibleFormDialogImplementation.this.onCancel(target, form);

            // resetExtensibleFormDialogImplementation(target);

            getDialog().hide(target);
        }
    });

    ExtensibleDialogButton submitButton = new ExtensibleDialogButton(submitText, true);

    submitButton.add(new AjaxFormSubmitBehavior(form, "click") {
        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            if (target != null) {
                resetFeedbackMessages(target);
            }

            if (ExtensibleFormDialogImplementation.this.onSubmit(target,
                    ExtensibleFormDialogImplementation.this.form)) {
                getDialog().hide(target);
            } else {
                target.add(ExtensibleFormDialogImplementation.this.alerts);
            }
        }

        @Override
        protected void onAfterSubmit(AjaxRequestTarget target) {
        }

        @Override
        protected void onError(AjaxRequestTarget target) {
            if (target != null) {
                // Visit each form component and if it is visible re-render it.
                // NOTE: We have to re-render every component to remove stale validation error messages.
                form.visitFormComponents((formComponent, iVisit) -> {
                    if ((formComponent.getParent() != null) && formComponent.getParent().isVisible()
                            && formComponent.isVisible()) {
                        target.add(formComponent);
                    }
                });
            }

            ExtensibleFormDialogImplementation.this.onError(target, form);
        }

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);

            // Do not allow normal form submit to happen
            attributes.setPreventDefault(true);
        }

        @Override
        public boolean getDefaultProcessing() {
            return submitButton.getDefaultFormProcessing();
        }

        @Override
        public boolean getStatelessHint(Component component) {
            return false;
        }
    });
    submitButton.setDefaultFormProcessing(true);

    List<ExtensibleDialogButton> buttons = new ArrayList<>();
    buttons.add(submitButton);
    buttons.add(cancelButton);

    return buttons;
}

From source file:name.martingeisse.trading_game.gui.self.BindPlayerToEmailAddressPanel.java

License:Open Source License

/**
 * Constructor/*from  w w  w . jav a  2  s. c o  m*/
 *
 * @param id the wicket id
 */
public BindPlayerToEmailAddressPanel(String id) {
    super(id);
    SimpleFormPanel formPanel = new SimpleFormPanel<BindPlayerToEmailAddressPanel>("formPanel",
            Model.of(this)) {
        @Override
        protected void onSubmit() {
            Player player = getPlayer();
            System.out.println(
                    "*** TODO send email to " + emailAddress + " with login token " + player.getLoginToken()); // TODO
            player.setEmailAddress(emailAddress);
            GuiNavigationUtil.setPanel(this, SelfPlayerPanel::new, AjaxRequestUtil.getAjaxRequestTarget());
        }
    };
    formPanel.prepareDecorator().withLabel("Email address").withModel("emailAddress").addTextField();
    formPanel.prepareSpecialFormBlock().withText("Send").addSubmitButton();
    formPanel.getForm().add(new AjaxFormSubmitBehavior("submit") {
        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            attributes.setPreventDefault(true);
        }
    }).setOutputMarkupId(true);
    add(formPanel);
}

From source file:name.martingeisse.trading_game.gui.self.RenamePlayerPanel.java

License:Open Source License

/**
 * Constructor/* w w w  .  j  a v a2  s.  co  m*/
 *
 * @param id the wicket id
 */
public RenamePlayerPanel(String id) {
    super(id);
    SimpleFormPanel formPanel = new SimpleFormPanel<RenamePlayerPanel>("formPanel", Model.of(this)) {
        @Override
        protected void onSubmit() {
            try {
                getPlayer().renameTo(newName);
                GuiNavigationUtil.setPanel(this, SelfPlayerPanel::new, AjaxRequestUtil.getAjaxRequestTarget());
            } catch (NameAlreadyUsedException e) {
                get("form:formBlocks:1:decoratedBody:textField").error("This name is already taken.");
            }
        }
    };
    formPanel.prepareDecorator().withLabel("New name").withModel("newName").addTextField();
    formPanel.prepareSpecialFormBlock().withText("Rename").addSubmitButton();
    formPanel.getForm().add(new AjaxFormSubmitBehavior("submit") {
        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            attributes.setPreventDefault(true);
        }
    }).setOutputMarkupId(true);
    add(formPanel);
    newName = getPlayer().getName();
}

From source file:org.wicketstuff.stateless.behaviors.StatelessAjaxFormSubmitBehavior.java

License:Apache License

@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
    super.updateAjaxAttributes(attributes);

    Form<?> form = findForm();//from w ww . j  a v a2  s  . c  om
    attributes.setFormId(form.getMarkupId());

    String formMethod = form.getMarkupAttributes().getString("method");
    if (formMethod == null || "POST".equalsIgnoreCase(formMethod)) {
        attributes.setMethod(Method.POST);
    }

    if (form.getRootForm().isMultiPart()) {
        attributes.setMultipart(true);
        attributes.setMethod(Method.POST);
    }

    attributes.setPreventDefault(true);
}

From source file:org.wicketstuff.stateless.components.StatelessAjaxButton.java

License:Apache License

protected StatelessAjaxFormSubmitBehavior newAjaxFormSubmitBehavior(String event) {
    return new StatelessAjaxFormSubmitBehavior(event) {
        private static final long serialVersionUID = 1L;

        @Override/*from   w  ww.j  ava  2s .c o m*/
        protected void onSubmit(AjaxRequestTarget target) {
            StatelessAjaxButton.this.onSubmit(target, StatelessAjaxButton.this.getForm());
        }

        @Override
        protected void onAfterSubmit(AjaxRequestTarget target) {
            StatelessAjaxButton.this.onAfterSubmit(target, StatelessAjaxButton.this.getForm());
        }

        @Override
        protected void onError(AjaxRequestTarget target) {
            StatelessAjaxButton.this.onError(target, StatelessAjaxButton.this.getForm());
        }

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);

            // do not allow normal form submit to happen
            attributes.setPreventDefault(true);

            StatelessAjaxButton.this.updateAjaxAttributes(attributes);
        }

        @Override
        protected Form<?> findForm() {
            return StatelessAjaxButton.this.getForm();
        }
    };
}

From source file:org.wicketstuff.stateless.components.StatelessAjaxFallbackLink.java

License:Apache License

public StatelessAjaxFallbackLink(final String id) {
    super(id);/*from  w  w  w .  j  a v a 2  s. c o  m*/

    add(new StatelessAjaxEventBehavior("click") {
        private static final long serialVersionUID = -8445395501430605953L;

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            attributes.setPreventDefault(true);
            StatelessAjaxFallbackLink.this.updateAjaxAttributes(attributes);
        }

        @Override
        protected void onComponentTag(final ComponentTag tag) {
            // only render handler if link is enabled
            if (isEnabledInHierarchy()) {
                super.onComponentTag(tag);
            }
        }

        @Override
        protected void onEvent(final AjaxRequestTarget target) {
            onClick(target);
            target.add(StatelessAjaxFallbackLink.this);
        }

        @Override
        protected PageParameters getPageParameters() {
            return getPage().getPageParameters();
        }
    });
}