use of org.apache.wicket.protocol.http.servlet.MultipartServletWebRequest in project wicket by apache.
the class Form method handleMultiPart.
/**
* Handles multi-part processing of the submitted data. <h3>
* WARNING</h3> If this method is overridden it can break {@link FileUploadField}s on this form
*
* @return false if form is multipart and upload failed
*/
protected boolean handleMultiPart() {
if (isMultiPart()) {
// parsed out correctly
try {
ServletWebRequest request = (ServletWebRequest) getRequest();
final MultipartServletWebRequest multipartWebRequest = request.newMultipartWebRequest(getMaxSize(), getPage().getId());
multipartWebRequest.setFileMaxSize(getFileMaxSize());
multipartWebRequest.parseFileParts();
// TODO: Can't this be detected from header?
getRequestCycle().setRequest(multipartWebRequest);
} catch (final FileUploadException fux) {
// Create model with exception and maximum size values
final Map<String, Object> model = new HashMap<>();
model.put("exception", fux);
model.put("maxSize", getMaxSize());
model.put("fileMaxSize", getFileMaxSize());
onFileUploadException(fux, model);
// don't process the form if there is a FileUploadException
return false;
}
}
return true;
}
use of org.apache.wicket.protocol.http.servlet.MultipartServletWebRequest in project wicket by apache.
the class AjaxFileDropBehavior method onEvent.
@Override
protected void onEvent(AjaxRequestTarget target) {
try {
ServletWebRequest request = (ServletWebRequest) getComponent().getRequest();
final MultipartServletWebRequest multipartWebRequest = request.newMultipartWebRequest(getMaxSize(), getComponent().getPage().getId());
multipartWebRequest.setFileMaxSize(getFileMaxSize());
multipartWebRequest.parseFileParts();
// TODO: Can't this be detected from header?
getComponent().getRequestCycle().setRequest(multipartWebRequest);
ArrayList<FileUpload> fileUploads = new ArrayList<>();
// Get the item for the path
final List<FileItem> fileItems = multipartWebRequest.getFile(parameterName);
if (fileItems != null) {
for (FileItem item : fileItems) {
fileUploads.add(new FileUpload(item));
}
}
onFileUpload(target, fileUploads);
} catch (final FileUploadException fux) {
onError(target, fux);
}
}
Aggregations