Search in sources :

Example 1 with AjaxFormSubmitBehavior

use of org.apache.wicket.ajax.form.AjaxFormSubmitBehavior in project midpoint by Evolveum.

the class UploadDownloadPanel method initLayout.

private void initLayout(final boolean isReadOnly) {
    final FileUploadField fileUpload = new FileUploadField(ID_INPUT_FILE);
    Form form = this.findParent(Form.class);
    fileUpload.add(new AjaxFormSubmitBehavior(form, "change") {

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            super.onSubmit(target);
            UploadDownloadPanel.this.uploadFilePerformed(target);
        }

        @Override
        protected void onError(AjaxRequestTarget target) {
            super.onError(target);
            UploadDownloadPanel.this.uploadFilePerformed(target);
        }
    });
    fileUpload.setOutputMarkupId(true);
    add(fileUpload);
    final AjaxDownloadBehaviorFromStream downloadBehavior = new AjaxDownloadBehaviorFromStream() {

        @Override
        protected InputStream initStream() {
            return getStream();
        }
    };
    add(downloadBehavior);
    add(new AjaxSubmitButton(ID_BUTTON_DOWNLOAD) {

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            downloadPerformed(downloadBehavior, target);
        }
    });
    add(new AjaxSubmitButton(ID_BUTTON_DELETE) {

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            removeFilePerformed(target);
        }
    });
    add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return !isReadOnly;
        }
    });
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxSubmitButton(com.evolveum.midpoint.web.component.AjaxSubmitButton) AjaxFormSubmitBehavior(org.apache.wicket.ajax.form.AjaxFormSubmitBehavior) Form(org.apache.wicket.markup.html.form.Form) AjaxDownloadBehaviorFromStream(com.evolveum.midpoint.web.component.AjaxDownloadBehaviorFromStream) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) FileUploadField(org.apache.wicket.markup.html.form.upload.FileUploadField)

Example 2 with AjaxFormSubmitBehavior

use of org.apache.wicket.ajax.form.AjaxFormSubmitBehavior in project midpoint by Evolveum.

the class NotificationConfigPanel method initLayout.

@Override
protected void initLayout() {
    TextField<String> defaultFromField = WebComponentUtil.createAjaxTextField(ID_DEFAULT_FROM, new PropertyModel<String>(getModel(), "defaultFrom"));
    CheckBox debugCheck = WebComponentUtil.createAjaxCheckBox(ID_DEBUG, new PropertyModel<Boolean>(getModel(), "debug"));
    DropDownChoice mailServerConfigChooser = new DropDownChoice<>(ID_MAIL_SERVER, new PropertyModel<MailServerConfigurationTypeDto>(getModel(), NotificationConfigurationDto.F_SELECTED_SERVER), new AbstractReadOnlyModel<List<MailServerConfigurationTypeDto>>() {

        @Override
        public List<MailServerConfigurationTypeDto> getObject() {
            return getModel().getObject().getServers();
        }
    }, new ChoiceableChoiceRenderer<MailServerConfigurationTypeDto>());
    mailServerConfigChooser.setNullValid(true);
    mailServerConfigChooser.add(new AjaxFormSubmitBehavior("click") {

        @Override
        protected void onEvent(AjaxRequestTarget target) {
            getForm().onFormSubmitted();
        }
    });
    mailServerConfigChooser.add(new OnChangeAjaxBehavior() {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            preparePasswordFieldPlaceholder();
            target.add(NotificationConfigPanel.this);
        }
    });
    add(mailServerConfigChooser);
    Label serverConfigTooltip = new Label(ID_MAIL_SERVER_TOOLTIP);
    serverConfigTooltip.add(new InfoTooltipBehavior());
    add(serverConfigTooltip);
    WebMarkupContainer serverConfigContainer = new WebMarkupContainer(ID_MAIL_SERVER_CONFIG_CONTAINER);
    serverConfigContainer.setOutputMarkupId(true);
    serverConfigContainer.setOutputMarkupPlaceholderTag(true);
    serverConfigContainer.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            if (getModelObject() != null) {
                return getModelObject().getSelectedServer() != null;
            }
            return false;
        }
    });
    add(serverConfigContainer);
    TextField<String> hostField = WebComponentUtil.createAjaxTextField(ID_HOST, new PropertyModel<String>(getModel(), "selectedServer.host"));
    TextField<Integer> portField = WebComponentUtil.createAjaxTextField(ID_PORT, new PropertyModel<Integer>(getModel(), "selectedServer.port"));
    TextField<String> userNameField = WebComponentUtil.createAjaxTextField(ID_USERNAME, new PropertyModel<String>(getModel(), "selectedServer.username"));
    PasswordTextField passwordField = new PasswordTextField(ID_PASSWORD, new PropertyModel<String>(getModel(), "selectedServer.password"));
    passwordField.setRequired(false);
    passwordField.add(new EmptyOnChangeAjaxFormUpdatingBehavior());
    TextField<String> redirectToFileField = WebComponentUtil.createAjaxTextField(ID_REDIRECT_TO_FILE, new PropertyModel<String>(getModel(), "redirectToFile"));
    DropDownFormGroup transportSecurity = new DropDownFormGroup<>(ID_TRANSPORT_SECURITY, new PropertyModel<MailTransportSecurityType>(getModel(), "selectedServer.mailTransportSecurityType"), WebComponentUtil.createReadonlyModelFromEnum(MailTransportSecurityType.class), new EnumChoiceRenderer<MailTransportSecurityType>(this), createStringResource("SystemConfigPanel.mail.transportSecurity"), ID_LABEL_SIZE, ID_INPUT_SIZE, false);
    // transportSecurity.add(new EmptyOnChangeAjaxFormUpdatingBehavior());
    serverConfigContainer.add(hostField);
    serverConfigContainer.add(portField);
    serverConfigContainer.add(userNameField);
    serverConfigContainer.add(passwordField);
    serverConfigContainer.add(transportSecurity);
    add(defaultFromField);
    add(debugCheck);
    add(redirectToFileField);
    AjaxSubmitLink buttonAddNewMailServerConfig = new AjaxSubmitLink(ID_BUTTON_ADD_NEW_MAIL_SERVER_CONFIG) {

        @Override
        protected void onSubmit(AjaxRequestTarget target, org.apache.wicket.markup.html.form.Form<?> form) {
            MailServerConfigurationTypeDto newConfig = new MailServerConfigurationTypeDto();
            newConfig.setHost(getString("SystemConfigPanel.mail.config.placeholder"));
            if (getModelObject() != null) {
                getModelObject().getServers().add(newConfig);
                getModelObject().setSelectedServer(newConfig);
            }
            preparePasswordFieldPlaceholder();
            target.add(NotificationConfigPanel.this, getPageBase().getFeedbackPanel());
        }

        @Override
        protected void onError(AjaxRequestTarget target, org.apache.wicket.markup.html.form.Form<?> form) {
            target.add(getPageBase().getFeedbackPanel());
        }
    };
    add(buttonAddNewMailServerConfig);
    AjaxSubmitLink removeMailServerConfig = new AjaxSubmitLink(ID_BUTTON_REMOVE_MAIL_SERVER_CONFIG) {

        @Override
        protected void onSubmit(AjaxRequestTarget target, org.apache.wicket.markup.html.form.Form<?> form) {
            if (getModelObject() != null) {
                NotificationConfigurationDto notificationConfig = getModelObject();
                MailServerConfigurationTypeDto selected = notificationConfig.getSelectedServer();
                if (notificationConfig.getServers().contains(selected)) {
                    notificationConfig.getServers().remove(selected);
                    notificationConfig.setSelectedServer(null);
                } else {
                    warn(getString("SystemConfigPanel.mail.server.remove.warn"));
                }
                target.add(NotificationConfigPanel.this, getPageBase().getFeedbackPanel());
            }
        }

        @Override
        protected void onError(AjaxRequestTarget target, org.apache.wicket.markup.html.form.Form<?> form) {
            target.add(getPageBase().getFeedbackPanel());
        }
    };
    removeMailServerConfig.add(new AttributeAppender("class", new AbstractReadOnlyModel<String>() {

        @Override
        public String getObject() {
            if (getModelObject() != null && getModelObject().getSelectedServer() != null) {
                return null;
            } else {
                return " disabled";
            }
        }
    }));
    add(removeMailServerConfig);
}
Also used : AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) Label(org.apache.wicket.markup.html.basic.Label) AjaxSubmitLink(org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxFormSubmitBehavior(org.apache.wicket.ajax.form.AjaxFormSubmitBehavior) MailServerConfigurationTypeDto(com.evolveum.midpoint.web.page.admin.configuration.dto.MailServerConfigurationTypeDto) List(java.util.List) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) AttributeAppender(org.apache.wicket.behavior.AttributeAppender) NotificationConfigurationDto(com.evolveum.midpoint.web.page.admin.configuration.dto.NotificationConfigurationDto) DropDownFormGroup(com.evolveum.midpoint.web.component.form.DropDownFormGroup) PasswordTextField(org.apache.wicket.markup.html.form.PasswordTextField) OnChangeAjaxBehavior(org.apache.wicket.ajax.form.OnChangeAjaxBehavior) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) InfoTooltipBehavior(com.evolveum.midpoint.web.util.InfoTooltipBehavior) MailTransportSecurityType(com.evolveum.midpoint.xml.ns._public.common.common_3.MailTransportSecurityType) DropDownChoice(org.apache.wicket.markup.html.form.DropDownChoice) CheckBox(org.apache.wicket.markup.html.form.CheckBox)

Example 3 with AjaxFormSubmitBehavior

use of org.apache.wicket.ajax.form.AjaxFormSubmitBehavior in project openmeetings by apache.

the class LangPanel method onInitialize.

@Override
protected void onInitialize() {
    // Create feedback panels
    add(feedback.setOutputMarkupId(true));
    language = new AbstractMap.SimpleEntry<>(1L, Locale.ENGLISH);
    final LabelsForm form = new LabelsForm("form", this, new StringLabel(null, null));
    form.showNewRecord();
    add(form);
    final SearchableDataView<StringLabel> dataView = new SearchableDataView<StringLabel>("langList", new SearchableDataProvider<StringLabel>(LabelDao.class) {

        private static final long serialVersionUID = 1L;

        @Override
        public long size() {
            return LabelDao.count(language.getValue(), search);
        }

        @Override
        public Iterator<? extends StringLabel> iterator(long first, long count) {
            return LabelDao.get(language.getValue(), search, (int) first, (int) count, getSort()).iterator();
        }
    }) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final Item<StringLabel> item) {
            final StringLabel fv = item.getModelObject();
            item.add(new Label("key"));
            item.add(new Label("value"));
            item.add(new AjaxEventBehavior(EVT_CLICK) {

                private static final long serialVersionUID = 1L;

                @Override
                protected void onEvent(AjaxRequestTarget target) {
                    form.setModelObject(fv);
                    form.hideNewRecord();
                    target.add(form, listContainer);
                    reinitJs(target);
                }
            });
            item.add(AttributeModifier.append(ATTR_CLASS, getRowClass(fv.getId(), form.getModelObject().getId())));
        }
    };
    add(listContainer.add(dataView).setOutputMarkupId(true));
    PagedEntityListPanel navigator = new PagedEntityListPanel("navigator", dataView) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onEvent(AjaxRequestTarget target) {
            dataView.modelChanging();
            target.add(listContainer);
        }
    };
    DataViewContainer<StringLabel> container = new DataViewContainer<>(listContainer, dataView, navigator);
    container.addLink(new OmOrderByBorder<>("orderByName", "key", container)).addLink(new OmOrderByBorder<>("orderByValue", "value", container));
    add(container.getLinks());
    add(navigator);
    langForm = new LangForm("langForm", listContainer, this);
    langForm.add(fileUploadField);
    langForm.add(new UploadProgressBar("progress", langForm, fileUploadField));
    fileUploadField.add(new AjaxFormSubmitBehavior(langForm, "change") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            FileUpload download = fileUploadField.getFileUpload();
            try {
                if (download == null || download.getInputStream() == null) {
                    feedback.error("File is empty");
                    return;
                }
                LabelDao.upload(language.getValue(), download.getInputStream());
            } catch (Exception e) {
                log.error("Exception on panel language editor import ", e);
                feedback.error(e);
            }
            // repaint the feedback panel so that it is hidden
            target.add(listContainer, feedback);
        }
    });
    // Add a component to download a file without page refresh
    final AjaxDownloadBehavior download = new AjaxDownloadBehavior(new ResourceStreamResource() {

        private static final long serialVersionUID = 1L;

        {
            setContentDisposition(ATTACHMENT);
            setCacheDuration(NONE);
        }

        @Override
        protected IResourceStream getResourceStream(Attributes attributes) {
            final String name = LabelDao.getLabelFileName(language.getValue());
            setFileName(name);
            return new AbstractResourceStream() {

                private static final long serialVersionUID = 1L;

                private transient InputStream is;

                @Override
                public InputStream getInputStream() throws ResourceStreamNotFoundException {
                    try {
                        is = Application.class.getResourceAsStream(name);
                        return is;
                    } catch (Exception e) {
                        throw new ResourceStreamNotFoundException(e);
                    }
                }

                @Override
                public void close() throws IOException {
                    if (is != null) {
                        is.close();
                        is = null;
                    }
                }
            };
        }
    });
    langForm.add(download);
    langForm.add(new AjaxButton("export") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            download.initiate(target);
            // repaint the feedback panel so that it is hidden
            target.add(feedback);
        }

        @Override
        protected void onError(AjaxRequestTarget target) {
            // repaint the feedback panel so errors are shown
            target.add(feedback);
        }
    });
    add(langForm);
    final AddLanguageDialog addLang = new AddLanguageDialog("addLang", this);
    add(addLang, new AjaxLink<Void>("addLangBtn") {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            addLang.open(target);
        }
    });
    add(BootstrapFileUploadBehavior.INSTANCE);
    add(new ConfirmableAjaxBorder("deleteLangBtn", getString("80"), getString("833")) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            LabelDao.delete(language.getValue());
            List<Map.Entry<Long, Locale>> langs = LangForm.getLanguages();
            language = langs.isEmpty() ? null : langs.get(0);
            langForm.updateLanguages(target);
            target.add(listContainer);
        }
    });
    super.onInitialize();
}
Also used : Locale(java.util.Locale) StringLabel(org.apache.openmeetings.db.entity.label.StringLabel) Label(org.apache.wicket.markup.html.basic.Label) StringLabel(org.apache.openmeetings.db.entity.label.StringLabel) LabelDao(org.apache.openmeetings.db.dao.label.LabelDao) AbstractMap(java.util.AbstractMap) SearchableDataView(org.apache.openmeetings.web.admin.SearchableDataView) Item(org.apache.wicket.markup.repeater.Item) AjaxFormSubmitBehavior(org.apache.wicket.ajax.form.AjaxFormSubmitBehavior) AjaxButton(com.googlecode.wicket.jquery.ui.form.button.AjaxButton) ResourceStreamResource(org.apache.wicket.request.resource.ResourceStreamResource) Iterator(java.util.Iterator) List(java.util.List) ResourceStreamNotFoundException(org.apache.wicket.util.resource.ResourceStreamNotFoundException) UploadProgressBar(org.apache.wicket.extensions.ajax.markup.html.form.upload.UploadProgressBar) FileUpload(org.apache.wicket.markup.html.form.upload.FileUpload) AbstractResourceStream(org.apache.wicket.util.resource.AbstractResourceStream) AjaxEventBehavior(org.apache.wicket.ajax.AjaxEventBehavior) IResourceStream(org.apache.wicket.util.resource.IResourceStream) InputStream(java.io.InputStream) ConfirmableAjaxBorder(org.apache.openmeetings.web.common.ConfirmableAjaxBorder) IOException(java.io.IOException) IOException(java.io.IOException) ResourceStreamNotFoundException(org.apache.wicket.util.resource.ResourceStreamNotFoundException) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) PagedEntityListPanel(org.apache.openmeetings.web.common.PagedEntityListPanel) OmOrderByBorder(org.apache.openmeetings.web.data.OmOrderByBorder) Map(java.util.Map) AbstractMap(java.util.AbstractMap) DataViewContainer(org.apache.openmeetings.web.data.DataViewContainer) AjaxDownloadBehavior(org.apache.wicket.extensions.ajax.AjaxDownloadBehavior)

Example 4 with AjaxFormSubmitBehavior

use of org.apache.wicket.ajax.form.AjaxFormSubmitBehavior in project midpoint by Evolveum.

the class UploadDownloadPanel method initLayout.

private void initLayout() {
    final FileUploadField fileUpload = new FileUploadField(ID_INPUT_FILE) {

        private static final long serialVersionUID = 1L;

        @Override
        public String[] getInputAsArray() {
            List<String> input = new ArrayList<>();
            try {
                input.add(new String(IOUtils.toByteArray(getStream())));
            } catch (IOException e) {
                LOGGER.error("Unable to define file content type: {}", e.getLocalizedMessage());
            }
            return input.toArray(new String[0]);
        }
    };
    Form form = this.findParent(Form.class);
    fileUpload.add(new AjaxFormSubmitBehavior(form, "change") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            super.onSubmit(target);
            UploadDownloadPanel.this.uploadFilePerformed(target);
        }

        @Override
        protected void onError(AjaxRequestTarget target) {
            super.onError(target);
            UploadDownloadPanel.this.uploadFilePerformed(target);
        }
    });
    fileUpload.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return !isReadOnly;
        }
    });
    fileUpload.setOutputMarkupId(true);
    add(fileUpload);
    final AjaxDownloadBehaviorFromStream downloadBehavior = new AjaxDownloadBehaviorFromStream() {

        private static final long serialVersionUID = 1L;

        @Override
        protected InputStream initStream() {
            InputStream is = getStream();
            try {
                String newContentType = URLConnection.guessContentTypeFromStream(is);
                if (StringUtils.isNotEmpty(newContentType)) {
                    setContentType(newContentType);
                }
            } catch (IOException ex) {
                LOGGER.error("Unable to define download file content type: {}", ex.getLocalizedMessage());
            }
            return is;
        }
    };
    downloadBehavior.setContentType(getDownloadContentType());
    downloadBehavior.setFileName(getDownloadFileName());
    add(downloadBehavior);
    add(new AjaxSubmitButton(ID_BUTTON_DOWNLOAD) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            downloadPerformed(downloadBehavior, target);
        }
    });
    AjaxSubmitButton deleteButton = new AjaxSubmitButton(ID_BUTTON_DELETE) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            removeFilePerformed(target);
        }
    };
    deleteButton.add(new VisibleBehaviour(() -> !isReadOnly));
    add(deleteButton);
    add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return !isReadOnly;
        }
    });
}
Also used : AjaxSubmitButton(com.evolveum.midpoint.web.component.AjaxSubmitButton) Form(org.apache.wicket.markup.html.form.Form) AjaxDownloadBehaviorFromStream(com.evolveum.midpoint.web.component.AjaxDownloadBehaviorFromStream) VisibleBehaviour(com.evolveum.midpoint.web.component.util.VisibleBehaviour) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) FileUploadField(org.apache.wicket.markup.html.form.upload.FileUploadField) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxFormSubmitBehavior(org.apache.wicket.ajax.form.AjaxFormSubmitBehavior) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)

Example 5 with AjaxFormSubmitBehavior

use of org.apache.wicket.ajax.form.AjaxFormSubmitBehavior in project wicket by apache.

the class BaseWicketTester method clickLink.

/**
 * Click the {@link Link} in the last rendered Page.
 * <p>
 * This method also works for {@link AjaxLink}, {@link AjaxFallbackLink} and
 * {@link AjaxSubmitLink}.
 * <p>
 * On AjaxLinks and AjaxFallbackLinks the onClick method is invoked with a valid
 * AjaxRequestTarget. In that way you can test the flow of your application when using AJAX.
 * <p>
 * When clicking an AjaxSubmitLink the form, which the AjaxSubmitLink is attached to is first
 * submitted, and then the onSubmit method on AjaxSubmitLink is invoked. If you have changed
 * some values in the form during your test, these will also be submitted. This should not be
 * used as a replacement for the {@link FormTester} to test your forms. It should be used to
 * test that the code in your onSubmit method in AjaxSubmitLink actually works.
 * <p>
 * This method is also able to simulate that AJAX (javascript) is disabled on the client. This
 * is done by setting the isAjax parameter to false. If you have an AjaxFallbackLink you can
 * then check that it doesn't fail when invoked as a normal link.
 *
 * @param path
 *            path to <code>Link</code> component
 * @param isAjax
 *            Whether to simulate that AJAX (javascript) is enabled or not. If it's false then
 *            AjaxLink and AjaxSubmitLink will fail, since it wouldn't work in real life.
 *            AjaxFallbackLink will be invoked with null as the AjaxRequestTarget parameter.
 */
public void clickLink(String path, boolean isAjax) {
    Component linkComponent = getComponentFromLastRenderedPage(path);
    checkUsability(linkComponent, true);
    // than a normal link
    if (linkComponent instanceof AjaxLink) {
        // If it's not ajax we fail
        if (isAjax == false) {
            fail("Link " + path + "is an AjaxLink and will " + "not be invoked when AJAX (javascript) is disabled.");
        }
        List<AjaxEventBehavior> behaviors = WicketTesterHelper.findAjaxEventBehaviors(linkComponent, "click");
        for (AjaxEventBehavior behavior : behaviors) {
            executeBehavior(behavior);
        }
    } else // from it using reflection so we know what to submit.
    if (linkComponent instanceof AjaxSubmitLink) {
        // If it's not ajax we fail
        if (isAjax == false) {
            fail("Link " + path + " is an AjaxSubmitLink and " + "will not be invoked when AJAX (javascript) is disabled.");
        }
        AjaxSubmitLink link = (AjaxSubmitLink) linkComponent;
        String pageRelativePath = link.getInputName();
        request.getPostParameters().setParameterValue(pageRelativePath, "x");
        submitAjaxFormSubmitBehavior(link, (AjaxFormSubmitBehavior) WicketTesterHelper.findAjaxEventBehavior(link, "click"));
    } else // if the link is an IAjaxLink, use it (do check if AJAX is expected)
    if (isAjax && (linkComponent instanceof IAjaxLink || linkComponent instanceof AjaxFallbackLink)) {
        List<AjaxEventBehavior> behaviors = WicketTesterHelper.findAjaxEventBehaviors(linkComponent, "click");
        for (AjaxEventBehavior behavior : behaviors) {
            executeBehavior(behavior);
        }
    } else /*
		 * If the link is a submitlink then we pretend to have clicked it
		 */
    if (linkComponent instanceof SubmitLink) {
        SubmitLink submitLink = (SubmitLink) linkComponent;
        String pageRelativePath = submitLink.getInputName();
        request.getPostParameters().setParameterValue(pageRelativePath, "x");
        serializeFormToRequest(submitLink.getForm());
        submitForm(submitLink.getForm().getPageRelativePath());
    } else if (linkComponent instanceof ExternalLink) {
        ExternalLink externalLink = (ExternalLink) linkComponent;
        String href = externalLink.getDefaultModelObjectAsString();
        try {
            getResponse().sendRedirect(href);
            recordRequestResponse();
            setupNextRequestCycle();
        } catch (IOException iox) {
            throw new WicketRuntimeException("An error occurred while redirecting to: " + href, iox);
        }
    } else // if the link is a normal link (or ResourceLink)
    if (linkComponent instanceof AbstractLink) {
        AbstractLink link = (AbstractLink) linkComponent;
        /*
			 * If the link is a bookmarkable link, then we need to transfer the parameters to the
			 * next request.
			 */
        if (link instanceof BookmarkablePageLink) {
            BookmarkablePageLink<?> bookmarkablePageLink = (BookmarkablePageLink<?>) link;
            try {
                Method getParametersMethod = BookmarkablePageLink.class.getDeclaredMethod("getPageParameters", (Class<?>[]) null);
                getParametersMethod.setAccessible(true);
                PageParameters parameters = (PageParameters) getParametersMethod.invoke(bookmarkablePageLink, (Object[]) null);
                startPage(bookmarkablePageLink.getPageClass(), parameters);
            } catch (Exception e) {
                throw new WicketRuntimeException("Internal error in WicketTester. " + "Please report this in Wicket's Issue Tracker.", e);
            }
        } else if (link instanceof ResourceLink) {
            try {
                Method getURL = ResourceLink.class.getDeclaredMethod("getURL", new Class[0]);
                getURL.setAccessible(true);
                CharSequence url = (CharSequence) getURL.invoke(link);
                executeUrl(url.toString());
            } catch (Exception x) {
                throw new RuntimeException("An error occurred while clicking on a ResourceLink", x);
            }
        } else {
            executeListener(link);
        }
    } else // The link requires AJAX
    if (linkComponent instanceof IAjaxLink && isAjax == false) {
        fail("Link " + path + "is an IAjaxLink and will " + "not be invoked when AJAX (javascript) is disabled.");
    } else {
        fail("Link " + path + " is not an instance of AbstractLink or IAjaxLink");
    }
}
Also used : AjaxEventBehavior(org.apache.wicket.ajax.AjaxEventBehavior) WicketRuntimeException(org.apache.wicket.WicketRuntimeException) AjaxFallbackLink(org.apache.wicket.ajax.markup.html.AjaxFallbackLink) AjaxSubmitLink(org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink) IAjaxLink(org.apache.wicket.ajax.markup.html.IAjaxLink) IOException(java.io.IOException) Method(java.lang.reflect.Method) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) ExternalLink(org.apache.wicket.markup.html.link.ExternalLink) WicketRuntimeException(org.apache.wicket.WicketRuntimeException) IOException(java.io.IOException) ParseException(java.text.ParseException) ResourceStreamNotFoundException(org.apache.wicket.util.resource.ResourceStreamNotFoundException) BookmarkablePageLink(org.apache.wicket.markup.html.link.BookmarkablePageLink) AjaxFormSubmitBehavior(org.apache.wicket.ajax.form.AjaxFormSubmitBehavior) WicketRuntimeException(org.apache.wicket.WicketRuntimeException) SubmitLink(org.apache.wicket.markup.html.form.SubmitLink) AjaxSubmitLink(org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink) ResourceLink(org.apache.wicket.markup.html.link.ResourceLink) Component(org.apache.wicket.Component) FormComponent(org.apache.wicket.markup.html.form.FormComponent) IAjaxLink(org.apache.wicket.ajax.markup.html.IAjaxLink) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) AbstractLink(org.apache.wicket.markup.html.link.AbstractLink)

Aggregations

AjaxFormSubmitBehavior (org.apache.wicket.ajax.form.AjaxFormSubmitBehavior)8 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)5 Form (org.apache.wicket.markup.html.form.Form)4 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)3 IOException (java.io.IOException)3 AjaxDownloadBehaviorFromStream (com.evolveum.midpoint.web.component.AjaxDownloadBehaviorFromStream)2 AjaxSubmitButton (com.evolveum.midpoint.web.component.AjaxSubmitButton)2 InputStream (java.io.InputStream)2 List (java.util.List)2 AjaxEventBehavior (org.apache.wicket.ajax.AjaxEventBehavior)2 AjaxSubmitLink (org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink)2 UploadProgressBar (org.apache.wicket.extensions.ajax.markup.html.form.upload.UploadProgressBar)2 Label (org.apache.wicket.markup.html.basic.Label)2 FileUploadField (org.apache.wicket.markup.html.form.upload.FileUploadField)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 DropDownFormGroup (com.evolveum.midpoint.web.component.form.DropDownFormGroup)1 VisibleBehaviour (com.evolveum.midpoint.web.component.util.VisibleBehaviour)1 MailServerConfigurationTypeDto (com.evolveum.midpoint.web.page.admin.configuration.dto.MailServerConfigurationTypeDto)1 NotificationConfigurationDto (com.evolveum.midpoint.web.page.admin.configuration.dto.NotificationConfigurationDto)1 InfoTooltipBehavior (com.evolveum.midpoint.web.util.InfoTooltipBehavior)1