use of org.apache.wicket.markup.html.form.upload.FileUploadField 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;
}
});
}
use of org.apache.wicket.markup.html.form.upload.FileUploadField in project wicket by apache.
the class FormTester method setFile.
/**
* Sets the <code>File</code> on a {@link FileUploadField}.
*
* @param formComponentId
* relative path (from <code>Form</code>) to the selectable
* <code>FormComponent</code>. The <code>FormComponent</code> must be of a type
* <code>FileUploadField</code>.
* @param file
* the <code>File</code> to upload or {@code null} for an empty input
* @param contentType
* the content type of the file. Must be a valid mime type.
* @return This
*/
public FormTester setFile(final String formComponentId, final File file, final String contentType) {
checkClosed();
FormComponent<?> formComponent = (FormComponent<?>) workingForm.get(formComponentId);
MockHttpServletRequest servletRequest = tester.getRequest();
if (formComponent instanceof FileUploadField) {
servletRequest.addFile(formComponent.getInputName(), file, contentType);
} else if (formComponent instanceof MultiFileUploadField) {
String inputName = formComponent.getInputName() + MultiFileUploadField.MAGIC_SEPARATOR + multiFileUploadIndex++;
servletRequest.addFile(inputName, file, contentType);
} else {
fail("'" + formComponentId + "' is not " + "a FileUploadField. You can only attach a file to form " + "component of this type.");
}
return this;
}
use of org.apache.wicket.markup.html.form.upload.FileUploadField 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;
}
});
}
use of org.apache.wicket.markup.html.form.upload.FileUploadField in project midpoint by Evolveum.
the class PageImportObject method initLayout.
private void initLayout() {
Form<?> mainForm = new MidpointForm<>(ID_MAIN_FORM);
mainForm.setMultiPart(true);
add(mainForm);
ImportOptionsPanel importOptions = new ImportOptionsPanel(ID_IMPORT_OPTIONS, optionsModel, fullProcessingModel);
mainForm.add(importOptions);
final WebMarkupContainer input = new WebMarkupContainer(ID_INPUT);
input.setOutputMarkupId(true);
mainForm.add(input);
WebMarkupContainer buttonBar = new WebMarkupContainer(ID_BUTTON_BAR);
buttonBar.setOutputMarkupId(true);
mainForm.add(buttonBar);
final IModel<Integer> groupModel = new Model<>(INPUT_FILE);
RadioGroup<Integer> importRadioGroup = new RadioGroup<>(ID_IMPORT_RADIO_GROUP, groupModel);
importRadioGroup.add(new AjaxFormChoiceComponentUpdatingBehavior() {
@Override
protected void onUpdate(AjaxRequestTarget target) {
target.add(input);
target.add(buttonBar);
}
});
mainForm.add(importRadioGroup);
Radio<Integer> fileRadio = new Radio<>(ID_FILE_RADIO, new Model<>(INPUT_FILE), importRadioGroup);
importRadioGroup.add(fileRadio);
Radio<Integer> xmlRadio = new Radio<>(ID_XML_RADIO, new Model<>(INPUT_XML), importRadioGroup);
importRadioGroup.add(xmlRadio);
WebMarkupContainer inputAce = new WebMarkupContainer(ID_INPUT_ACE);
addVisibileForInputType(inputAce, INPUT_XML, groupModel);
input.add(inputAce);
dataLanguage = determineDataLanguage();
DataLanguagePanel<List> languagePanel = new DataLanguagePanel<List>(ID_LANGUAGE_PANEL, dataLanguage, List.class, this) {
@Override
protected void onLanguageSwitched(AjaxRequestTarget target, int index, String updatedLanguage, String objectString) {
dataLanguage = updatedLanguage;
xmlEditorModel.setObject(objectString);
addOrReplaceEditor(inputAce);
target.add(mainForm);
}
@Override
protected String getObjectStringRepresentation() {
return xmlEditorModel.getObject();
}
};
inputAce.add(languagePanel);
addOrReplaceEditor(inputAce);
WebMarkupContainer inputFileLabel = new WebMarkupContainer(ID_INPUT_FILE_LABEL);
addVisibileForInputType(inputFileLabel, INPUT_FILE, groupModel);
input.add(inputFileLabel);
WebMarkupContainer inputFile = new WebMarkupContainer(ID_INPUT_FILE);
addVisibileForInputType(inputFile, INPUT_FILE, groupModel);
input.add(inputFile);
FileUploadField fileInput = new FileUploadField(ID_FILE_INPUT);
inputFile.add(fileInput);
initButtons(buttonBar, groupModel);
}
use of org.apache.wicket.markup.html.form.upload.FileUploadField in project midpoint by Evolveum.
the class PageNewReport method initLayout.
private void initLayout() {
Form mainForm = new Form(ID_MAIN_FORM);
add(mainForm);
final WebMarkupContainer input = new WebMarkupContainer(ID_INPUT);
input.setOutputMarkupId(true);
mainForm.add(input);
final WebMarkupContainer buttonBar = new WebMarkupContainer(ID_BUTTON_BAR);
buttonBar.setOutputMarkupId(true);
mainForm.add(buttonBar);
final IModel<Integer> groupModel = new Model<Integer>(INPUT_FILE);
RadioGroup importRadioGroup = new RadioGroup(ID_IMPORT_RADIO_GROUP, groupModel);
importRadioGroup.add(new AjaxFormChoiceComponentUpdatingBehavior() {
@Override
protected void onUpdate(AjaxRequestTarget target) {
target.add(input);
target.add(buttonBar);
}
});
mainForm.add(importRadioGroup);
Radio fileRadio = new Radio(ID_FILE_RADIO, new Model(INPUT_FILE), importRadioGroup);
importRadioGroup.add(fileRadio);
Radio xmlRadio = new Radio(ID_XML_RADIO, new Model(INPUT_XML), importRadioGroup);
importRadioGroup.add(xmlRadio);
WebMarkupContainer inputAce = new WebMarkupContainer(ID_INPUT_ACE);
addVisibileForInputType(inputAce, INPUT_XML, groupModel);
input.add(inputAce);
AceEditor aceEditor = new AceEditor(ID_ACE_EDITOR, xmlEditorModel);
aceEditor.setOutputMarkupId(true);
inputAce.add(aceEditor);
WebMarkupContainer inputFileLabel = new WebMarkupContainer(ID_INPUT_FILE_LABEL);
addVisibileForInputType(inputFileLabel, INPUT_FILE, groupModel);
input.add(inputFileLabel);
WebMarkupContainer inputFile = new WebMarkupContainer(ID_INPUT_FILE);
addVisibileForInputType(inputFile, INPUT_FILE, groupModel);
input.add(inputFile);
FileUploadField fileInput = new FileUploadField(ID_FILE_INPUT);
inputFile.add(fileInput);
initButtons(buttonBar, groupModel);
}
Aggregations