Search in sources :

Example 1 with SubmitLink

use of org.apache.wicket.markup.html.form.SubmitLink in project wicket by apache.

the class StatelessPageWithFeedback method onInitialize.

@Override
protected void onInitialize() {
    super.onInitialize();
    setStatelessHint(true);
    error("error in onInitialize");
    add(new FeedbackPanel("feedback"));
    StatelessForm<Void> form = new StatelessForm<Void>("form");
    add(form);
    form.add(new SubmitLink("submit") {

        private static final long serialVersionUID = 1L;

        @Override
        public void onSubmit() {
            StatelessPageWithFeedback.this.error("error in onSubmit");
        }
    });
}
Also used : FeedbackPanel(org.apache.wicket.markup.html.panel.FeedbackPanel) SubmitLink(org.apache.wicket.markup.html.form.SubmitLink) StatelessForm(org.apache.wicket.markup.html.form.StatelessForm)

Example 2 with SubmitLink

use of org.apache.wicket.markup.html.form.SubmitLink in project the-app by devops-dojo.

the class CheckoutPage method submitOrderLink.

private Component submitOrderLink() {
    return new SubmitLink("submitOrder") {

        private static final long serialVersionUID = 5203227218130238529L;

        @Override
        protected void onBeforeRender() {
            setVisible(!isReadOnly() && getAuthenticationService().isAuthorized());
            super.onBeforeRender();
        }

        @Override
        public void onSubmit() {
            OrderInfo submittedOrder = orderService.submitOrder(orderInfoModel.getObject(), getSession().getId());
            trackingService.trackPurchase(submittedOrder);
            getSession().info(CheckoutPage.this.getString("order.submitted"));
            setResponsePage(new OrderConfirmationPage(Model.of(submittedOrder)));
        }
    };
}
Also used : SubmitLink(org.apache.wicket.markup.html.form.SubmitLink) OrderInfo(io.github.zutherb.appstash.shop.service.order.model.OrderInfo)

Example 3 with SubmitLink

use of org.apache.wicket.markup.html.form.SubmitLink 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)

Example 4 with SubmitLink

use of org.apache.wicket.markup.html.form.SubmitLink in project the-app by devops-dojo.

the class DeliveryAdressEditPanel method deliveryAdressEditForm.

private Component deliveryAdressEditForm() {
    Form<OrderInfo> deliveryAdressEditForm = new Form<>("deliveryAdressEditForm");
    deliveryAdressEditForm.add(new TextField<>("firstname", new PropertyModel<>(orderModel, "deliveryAddress.firstname")).setRequired(true));
    deliveryAdressEditForm.add(new TextField<>("lastname", new PropertyModel<>(orderModel, "deliveryAddress.lastname")).setRequired(true));
    deliveryAdressEditForm.add(new TextField<>("street", new PropertyModel<>(orderModel, "deliveryAddress.street")).setRequired(true));
    deliveryAdressEditForm.add(new TextField<>("zip", new PropertyModel<>(orderModel, "deliveryAddress.zip")).setRequired(true));
    deliveryAdressEditForm.add(new TextField<>("city", new PropertyModel<>(orderModel, "deliveryAddress.city")).setRequired(true));
    deliveryAdressEditForm.add(new SubmitLink("deliveryAdressEditFormSubmit") {

        private static final long serialVersionUID = 8821619700889289116L;

        @Override
        public void onSubmit() {
            deliveryAdressEditFormSubmit();
        }
    });
    return deliveryAdressEditForm;
}
Also used : Form(org.apache.wicket.markup.html.form.Form) SubmitLink(org.apache.wicket.markup.html.form.SubmitLink) TextField(org.apache.wicket.markup.html.form.TextField) OrderInfo(io.github.zutherb.appstash.shop.service.order.model.OrderInfo)

Aggregations

SubmitLink (org.apache.wicket.markup.html.form.SubmitLink)4 OrderInfo (io.github.zutherb.appstash.shop.service.order.model.OrderInfo)2 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 ParseException (java.text.ParseException)1 Component (org.apache.wicket.Component)1 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)1 AjaxEventBehavior (org.apache.wicket.ajax.AjaxEventBehavior)1 AjaxFormSubmitBehavior (org.apache.wicket.ajax.form.AjaxFormSubmitBehavior)1 AjaxFallbackLink (org.apache.wicket.ajax.markup.html.AjaxFallbackLink)1 AjaxLink (org.apache.wicket.ajax.markup.html.AjaxLink)1 IAjaxLink (org.apache.wicket.ajax.markup.html.IAjaxLink)1 AjaxSubmitLink (org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink)1 Form (org.apache.wicket.markup.html.form.Form)1 FormComponent (org.apache.wicket.markup.html.form.FormComponent)1 StatelessForm (org.apache.wicket.markup.html.form.StatelessForm)1 TextField (org.apache.wicket.markup.html.form.TextField)1 AbstractLink (org.apache.wicket.markup.html.link.AbstractLink)1 BookmarkablePageLink (org.apache.wicket.markup.html.link.BookmarkablePageLink)1 ExternalLink (org.apache.wicket.markup.html.link.ExternalLink)1