use of org.apache.wicket.markup.html.form.upload.MultiFileUploadField 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;
}
Aggregations