Search in sources :

Example 6 with AjaxFormSubmitBehavior

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

the class BaseWicketTester method executeBehavior.

/**
 * Builds and processes a request suitable for executing an <code>AbstractAjaxBehavior</code>.
 *
 * @param behavior
 *            an <code>AbstractAjaxBehavior</code> to execute
 */
public void executeBehavior(final AbstractAjaxBehavior behavior) {
    Args.notNull(behavior, "behavior");
    Url url = Url.parse(behavior.getCallbackUrl().toString(), Charset.forName(request.getCharacterEncoding()));
    transform(url);
    request.setUrl(url);
    request.addHeader(WebRequest.HEADER_ORIGIN, createOriginHeader());
    request.addHeader(WebRequest.HEADER_AJAX_BASE_URL, url.toString());
    request.addHeader(WebRequest.HEADER_AJAX, "true");
    if (behavior instanceof AjaxFormSubmitBehavior) {
        AjaxFormSubmitBehavior formSubmitBehavior = (AjaxFormSubmitBehavior) behavior;
        Form<?> form = formSubmitBehavior.getForm();
        getRequest().setUseMultiPartContentType(form.isMultiPart());
        serializeFormToRequest(form);
        // mark behavior's component as the form submitter,
        String name = Form.getRootFormRelativeId(new PropertyModel<Component>(behavior, "component").getObject());
        if (!request.getPostParameters().getParameterNames().contains(name)) {
            request.getPostParameters().setParameterValue(name, "marked");
        }
    }
    processRequest();
}
Also used : AjaxFormSubmitBehavior(org.apache.wicket.ajax.form.AjaxFormSubmitBehavior) PropertyModel(org.apache.wicket.model.PropertyModel) Url(org.apache.wicket.request.Url)

Example 7 with AjaxFormSubmitBehavior

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

the class UploadableImagePanel method onInitialize.

@Override
protected void onInitialize() {
    super.onInitialize();
    final Form<Void> form = new Form<>("form");
    form.setMultiPart(true);
    form.setMaxSize(Bytes.bytes(getMaxUploadSize()));
    // Model is necessary here to avoid writing image to the User object
    form.add(fileUploadField);
    form.add(new UploadProgressBar("progress", form, fileUploadField));
    fileUploadField.add(new AjaxFormSubmitBehavior(form, "change") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            FileUpload fu = fileUploadField.getFileUpload();
            if (fu != null) {
                File temp = null;
                try {
                    temp = fu.writeToTempFile();
                    StoredFile sf = new StoredFile(fu.getClientFileName(), temp);
                    if (sf.isImage()) {
                        processImage(sf, temp);
                    }
                } catch (Exception e) {
                    log.error("Error", e);
                } finally {
                    if (temp != null && temp.exists()) {
                        log.debug("Temp file was deleted ? {}", temp.delete());
                    }
                    fu.closeStreams();
                    fu.delete();
                }
            }
            update();
            target.add(profile, form);
        }
    });
    add(form.setOutputMarkupId(true));
    add(BootstrapFileUploadBehavior.INSTANCE);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxFormSubmitBehavior(org.apache.wicket.ajax.form.AjaxFormSubmitBehavior) Form(org.apache.wicket.markup.html.form.Form) StoredFile(org.apache.openmeetings.util.StoredFile) UploadProgressBar(org.apache.wicket.extensions.ajax.markup.html.form.upload.UploadProgressBar) File(java.io.File) StoredFile(org.apache.openmeetings.util.StoredFile) FileUpload(org.apache.wicket.markup.html.form.upload.FileUpload)

Example 8 with AjaxFormSubmitBehavior

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

the class MidPointApplication method isPostMethodTypeBehavior.

private boolean isPostMethodTypeBehavior(AbstractDefaultAjaxBehavior behavior, AjaxRequestAttributes attributes) {
    if (behavior instanceof AjaxFormComponentUpdatingBehavior) {
        // these also uses POST, but they set it after this method is called
        return true;
    }
    if (behavior instanceof AjaxFormSubmitBehavior) {
        AjaxFormSubmitBehavior fb = (AjaxFormSubmitBehavior) behavior;
        Form form = fb.getForm();
        String formMethod = form.getMarkupAttributes().getString("method");
        if (formMethod == null || "POST".equalsIgnoreCase(formMethod) || form.getRootForm().isMultiPart()) {
            // this will also use POST
            return true;
        }
    }
    return AjaxRequestAttributes.Method.POST.equals(attributes.getMethod());
}
Also used : AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) AjaxFormSubmitBehavior(org.apache.wicket.ajax.form.AjaxFormSubmitBehavior) Form(org.apache.wicket.markup.html.form.Form) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

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