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();
}
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);
}
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());
}
Aggregations